0

here's my problem:

Chrome console:

    Uncaught ReferenceError: jQuery is not defined jquery-ui.min.js:6
    Uncaught ReferenceError: jQuery is not defined slider.js:1
    Uncaught ReferenceError: jQuery is not defined functions.js:1
    Uncaught ReferenceError: jQuery is not defined menu_mobile.js:1
    Uncaught Error: Bootstrap's JavaScript requires jQuery 

I enqueue my scripts before wp_head() in header.php:

<?php
        function frontEnd_scripts() {
            wp_enqueue_script("jquery");
            wp_deregister_script('jquery.mobile');
            wp_register_script('jquery.mobile', ("//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js"),array('jquery'));
            wp_enqueue_script('jquery.mobile');
            wp_register_style('jqm_css',('//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.css'));
            wp_enqueue_style('jqm_css');

        }
        add_action('wp_enqueue_scripts', 'frontEnd_scripts'); 
    ?>
    <?php wp_head(); ?>
    <!-- My custom scripts here -->

I tried to enqueue my custom scripts with no results.

js files wrapped like this:

jQuery(document).ready(function($j){
    // Do some stuff
});

Everything works fine on a local MAMP server but it does not work on web server and the only way I can make it work is to hardcode the jQuery script tag before the wp-head(). Is it possible that my online version of wordpress don't have jQuery included or removed ?

Thanks !

1 Answer 1

1

Add this in functions.php instead of header.php

function frontEnd_scripts() {
    wp_enqueue_script("jquery");
    wp_deregister_script('jquery.mobile');
    wp_register_script('jquery.mobile', ("//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js"),array('jquery'));
    wp_enqueue_script('jquery.mobile');
    wp_register_style('jqm_css',('//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.css'));
    wp_enqueue_style('jqm_css');
}
add_action('wp_enqueue_scripts', 'frontEnd_scripts'); 
1
  • Thanks @Robert ! Works perfectly ! I thought that the euqueues must be in header.php, what is the difference ?
    – Berthy
    Commented Sep 11, 2014 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.