• Looked around for a bit and could not find an answer. Maybe I’m using bad keywords.

    I have installed wordpress and have the default Twenty Fifteen theme activated.

    This is a new install and I have changed nothing to the files.

    When I check the Sources tab in Chrome Developers tool, it shows jQuery is being loaded from:
    wp-includes/js/jquery/jquery.js?ver=1.11.1

    If I check the page source I can clearly see in the head jquery is being loaded.

    <script type='text/javascript' src='http://yourdomain.com/wp-includes/js/jquery/jquery.js?ver=1.11.1'></script>
    <script type='text/javascript' src='http://yourdomain.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>

    So to test whether or not jQuery commands are working or not I put a:

    <script>
    $( document ).ready(function() {
    	alert("hello");
    });
    </script>

    At the end of the footer.php file.

    And it does NOT work. If i strip out the jquery $( document ).ready(function() { … }); stuff then the alert pops up.

    If i include jQuery via CDN in the head section (header.php), then the jquery $( document ).ready(function() { ... }); does work.
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    (I know you have to use enque and register in fucntions.php to properly load JS)

    So my question is what is the wp-includes/js/jquery/jquery.js?ver=1.11.1 file all about? Why is it being loaded if it doesn’t even execute basic jquery?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Dear comicBookGuy .
    At the end of the footer.php file no script,session,global data not working.
    So,You Add js File in ur theme function.php file
    like this
    function.php

    function add_stayle(){
    wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
    }
    add_action( 'wp_enqueue_scripts','add_stayle');

    Note:
    example.js is ur js file name.

    Thank’s
    Dev

    Enjoy..!!

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    The reason is because jQuery in WordPress is set to noConflict()

    You can read about it here: http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers

    So this will work:

    jQuery( document ).ready( function( $ ) {
        // Can use $ for jQuery
        var el = $( '.class' );
    } );

    Alternatively you can use:

    ( function( $ ){
        var el = $( '#elementid' );
    } )( jQuery );

    Thread Starter comicBookGuy

    (@comicbookguy)

    ty Jose.

    for future reference this is what I found from the suggested reading:

    jQuery(document).ready(function($) {
    // Inside of this function, $() will work as an alias for jQuery()
    // and other libraries also using $ will not be accessible under this shortcut
    });

    That wrapper will cause your code to be executed when the DOM is fully constructed. If, for some reason, you want your code to execute immediately instead of waiting for the DOM ready event, then you can use this wrapper method instead:

    (function($) {
    // Inside of this function, $() will work as an alias for jQuery()
    // and other libraries also using $ will not be accessible under this shortcut
    })(jQuery);

    Alternatively, you can always reasign jQuery to another shortcut of your choice and leave the $ shorcut to other libraries:

    var $j = jQuery;

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘local jQuery not working?’ is closed to new replies.