Archived topic
enable jquery in GP hooks
5 replies · Started by Hung on October 18, 2021
Using the guide here, I can enable jQuery. However, I would like to use GP wp_footer hook for enabling jQuery per page. Is that possible? I made some searches, but could not find anything.
Thanks.
Hi there,
this line:
wp_enqueue_script( 'jquery' );
can be changed to:
wp_enqueue_script( 'jquery' , '', array(), true);
BUT... if you have any scripts loading before the footer that are dependent on jQuery those scripts will most likely break. I personally wouldn't recommend doing this unless you have full control over how the dependent scripts are loaded.
Thanks for both solution and warning :) No, I don't have any other script, that's also the reason that I want to enable jquery per page only, not the whole site.
If we go back to Toms script ie. this:
add_action( 'wp_enqueue_scripts', 'tu_load_jquery' );
function tu_load_jquery() {
wp_enqueue_script( 'jquery' );
}
You would need to add a conditional tag for example:
add_action( 'wp_enqueue_scripts', 'tu_load_jquery' );
function tu_load_jquery() {
if ( is_page( 'the-page-slug-you-want-script-on' ) ) {
wp_enqueue_script( 'jquery' );
}
}
Yes, I am aware of the conditional tag. However, I would like to use GP Elements for avoiding the risk when the customer updates functions.php file.
Hmmm... not sure if this will work but you can try adding Tom's script in a wp_head hook.
The wp_enqueue_scripts hook fires after the wp_head so it may work.... but as a general note the Hook Element is built for inserting content into the templates.