• Hi, what is right approach to include jquery scripts on my template. I created custom theme with functions.php including this:

    function include_my_scripts() {
        ...
        wp_enqueue_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', array(), '20160801', false ); // jquery to header
        wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/js/custom.js', array('jquery'), '20160819', true );
        ...
        }
        add_action( 'wp_enqueue_scripts', 'include_my_scripts' );

    Despite that in my rendered page i see:
    – in header after <title>: <script type='text/javascript' src='http://www.mypage.com/new/wp-includes/js/jquery/jquery.js?ver=1.12.4'></script> (why jquery is load from my site and why $ is not working in next scripts?)
    – in footer: <script type=’text/javascript’ src=’http://www.mypage.com/new/wp-content/themes/mytheme/js/custom.js?ver=20160819′></script&gt; (which is correct, i think)

    But nothing from custom.js is not working.

    And this is console output:
    – custom.js?ver=20160819:1 Uncaught TypeError: $ is not a function(anonymous function) @ custom.js?ver=20160819:1

    How can I remove Uncaught TypeError: $ is not a function?
    If I include jQuery to footer before my custom.js, then everything is ok.

    Thanks

The topic ‘right use of wp_enqueue_script for jquery’ is closed to new replies.