I want a javascript / css library to load only when a view is loaded.
Since there's no php allowed in Views, I created a shortcode [dmo_enqueue_splide] which loads the necessary files using the wp_enqueue_script and wp_enqueue_style function. I registered this shortcode as a third party shortcode. But views doesn't run it, it just outputs [dmo_enqueue_splide].
I'm aware I can load the files using <script> and <link> tags.
But then I have no control over the location of the files (I want them in the footer) and the files can be loaded multiple times of multiple views are loaded, or other components which use the same libraries.
Any suggestions?
Hello and thank you for contacting the Toolset support.
If you get [dmo_enqueue_splide] in the frontend instead of what it should do, I would suspect that the shortcode is not correctly registered. To confirm that, please switch to a default theme and deactivate all plugins including Toolset ones, then add that shortcode to a page or post and check if it works as expected. If it works, we can investigate why is it not working with Toolset views. If it does not, it would mean that the shortcode is not correctly registered.
I hope this helps. Otherwise, please explain where did you add the shortcode code/definition and share the code here to let us check it too.
Indeed, there was a typo in my function that registered the shortcode. I wrongly assumed that views wasn't processing the shortcode. It works fine now.
Thanks!