Navigation überspringen

[Gelöst] Load an external js file when page contains a view

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
Load an external js file when page contains a view

Solution:
You should have to build an array of page IDs where you added your view and then use that array with if condition to check if current post/page ID is available with the array value, then you can enqueue the js.

Relevant Documentation:

This support ticket is created vor 4 Jahre, 1 Monat. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Paul Marconi vor 4 Jahre, 1 Monat.

Assistiert von: Minesh.

Author
Artikel
#2079833

Hi,

With the 'Toolset Views' plugin, we have created couple of views to list CPT.
Currently, we have an external .js file enqueue in the functions.php file, so it's loading in all pages.
However, we want to have that js file loaded when a page contains a toolset view.
Is there a way to check if the current page contains a view? Therefore, we can include an if statement in the functions.php file to load that specific file if it's true.

Thank you!

#2080013

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no way to check if page has view added or not.

I think the way is to build an array of page IDs where you added your view and then use that array with if condition to check if current post/page ID is available with the array value, then you can enqueue the js.

#2080583

Thanks Minesh!
Just wondering, is there a way to check if the current page contains a certain class or ID name?
Say if the current page contains the classname "has-view", in the functions.php file we can add an if statement to enqueue other js or css files.

Is there s way to do that in wordpress?

Thank you!

#2081113

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

We can check that using the jQuery but not using PHP.

The workaround I shared is better to go with page IDs.

#2084663

Thanks Minesh!