Archived topic
How to add jquery if not using the sticky navigation module
7 replies · Started by Gary on July 11, 2022
Hi Support
Hopefully a simple request, I want to use an Elements hook to enqueue jquery on a couple of pages using a slider which still requires jquery.
By default the slider doesn't work because GP isn't including jquery as I'm not using the sticky nav which I believe is the only thing in GP that still requires jquery.
So what is the best way to add jquery manually for a couple of pages? I've found this code mentioned in previous threads but it doesn't seem to work for me:
add_action( 'wp_enqueue_scripts', 'tu_load_jquery' );
function tu_load_jquery() {
wp_enqueue_script( 'jquery' );
}
Thanks
Hi there,
That code should still work.
Can you make sure that it's added using one of these methods?
Adding PHP: https://docs.generatepress.com/article/adding-php/
Hi Leo
Is there a reason I shouldn’t use an Element hook for this with tge execute php option checked?
That’s what I’m doing currently.
Thanks
Hmm because it's a function and not a hook content.
OK sorry, should have made myself clearer, I am using a hook element set to wp_footer in this case, which I’m trying to then enqueue jquery with using the snippet mentioned above. That should work correct?
Thanks
No, your method would work if the PHP code outputs content or if it's a script.
But it's a PHP function, it should be added using one of the methods introduced here:https://docs.generatepress.com/article/adding-php/
Hi Ying
OK thanks for clarifying. In that case I’ll use the snippets plugin.
Thanks
No problem :)