I have a very simple JS script called script_1.js sitting at the root level of my twentytwelve-child theme. This script contains only:
$(document).ready(function(){console.log("scriptLoaded");
});
and I've loaded it with the functions.php:
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style',
get_template_directory_uri() . '/style.css'
);
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( 'parent-style' )
);
}
function wpb_adding_scripts() {
wp_register_script( 'my_script',
get_stylesheet_directory_uri() . '/script_1.js',
array( 'jquery' ),
null,
true
);
wp_enqueue_script( 'my_script' );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
Now, I read the documentation and I found that if I want to put jQuery first, I have to use the above syntax, hence array( 'jquery' ).
The problem is, that it still doesn't work and in the console I still get the usual:
TypeError: $ is not a function
$(document).ready(function(){
There is a link where you can see the problem occurring, here it is (error in the console).
Does anybody know why this isn't working? Did I incorrectly enqueue jQuery or something? I've seen a few examples, like this one and that's where I took inspiration from, but no joy.