[Resolved] enable jquery in GP hooks

Home Forums Support [Resolved] enable jquery in GP hooks

Home Forums Support enable jquery in GP hooks

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1966952
    Hung

    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.

    #1967028
    David
    Staff
    Customer Support

    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.

    #1967036
    Hung

    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.

    #1967056
    David
    Staff
    Customer Support

    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' );
        }
    }
    #1967070
    Hung

    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.

    #1967078
    David
    Staff
    Customer Support

    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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.