• tkse

    (@tkse)


    Hi.

    How should I go about including jQuery in 3.3.1? Every way I can think of either create problems with the admin-bar (hiding it) or it won’t work.

    I have Googled for other ways, but it doesn’t do anything good.

Viewing 15 replies - 1 through 15 (of 22 total)
  • esmi

    (@esmi)

    jQuery is already available in WP 3.3.1. Perhaps you need to review wp_enqueue_script?

    Thread Starter tkse

    (@tkse)

    I must have missed something, because that didn’t help.

    esmi

    (@esmi)

    I’m sorry but all of the information that you need is on that page.

    Thread Starter tkse

    (@tkse)

    I guess me being a newbie at this doesnt help, but, more right to the point.

    How to write jQuery in a template-file? What I got from that is to add the script under “Load a default WordPress script from a non-default location”. :S

    esmi

    (@esmi)

    Is the script you want to load within your theme or located elsewhere?

    Thread Starter tkse

    (@tkse)

    The jQuery-script I have written(?) is in my sidebar.php theme-file. The jQuery source-file is on the Google API-site.

    I’m sorry if I dont understand everything, being bad at English doesnt help my situation. ??

    esmi

    (@esmi)

    Take your script out of your sidebar file, save it as a standalone script and then enqueue it – eg:

    <?php
    function my_scripts_method() {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'google-jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
        wp_enqueue_script( 'google-jquery' );
        wp_register_script( 'my-jquery', get_template_directory_uri() . '/my-script.js', 'google-jquery');
        wp_enqueue_script( 'my-jquery' );
    }    
    
    add_action('wp_enqueue_scripts', 'my_scripts_method');
    ?>
    Thread Starter tkse

    (@tkse)

    Okey, so I did what you suggested.

    I took my script out of sidebar.php and into a new file, myjquery.js inside the js-directory.

    Then, I posted this in my functions.php-file:

    function my_scripts_method() {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'google-jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
        wp_enqueue_script( 'google-jquery' );
        wp_register_script( 'my-jquery', get_template_directory_uri() . 'js/myjquery.js', 'google-jquery');
        wp_enqueue_script( 'my-jquery' );
    }    
    
    add_action('wp_enqueue_scripts', 'my_scripts_method');

    I also tried seperating it into its own PHP-tag. It didn’t work unfortunaly.

    esmi

    (@esmi)

    That was just an example! you have to substitute your own script location and the correct Google jQuery call.

    Thread Starter tkse

    (@tkse)

    I did, didnt I? ??

    I can try with the 1.7.1-link.

    fordp

    (@fordp)

    I think you need a slash before js/myjquery.js

    ie:

    function my_scripts_method() {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'google-jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
        wp_enqueue_script( 'google-jquery' );
        wp_register_script( 'my-jquery', get_template_directory_uri() . '/js/myjquery.js', 'google-jquery');
        wp_enqueue_script( 'my-jquery' );
    }    
    
    add_action('wp_enqueue_scripts', 'my_scripts_method');
    Thread Starter tkse

    (@tkse)

    Tried it, tried full URL, doesn’t work. And it still creates a problem with the admin-bar.

    fordp

    (@fordp)

    Can you post your sites URL so I can take a quick look

    Thread Starter tkse

    (@tkse)

    Go ahead: https://goo.gl/Cpq2E ??

    But I did some troubleshooting myself, and there is two main problems. It cant find the jquery file and it looks for a text/html-file, not javascript.

    Thread Starter tkse

    (@tkse)

    I was able to fix it. ??

    In the end it was just sloppy mistakes ruining it for me.

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Problem with including jQuery’ is closed to new replies.