I’m trying to load masonry but I’m having no luck, I’ve managed to load it manually but then I realised it was included in the wordpress core, so I thought oh that’s handy.
I have it enqueue’ (I really hate that word) like this:
function lart_front_end_scripts() {
if (is_admin()) return;
wp_enqueue_script('jquery', '1.10.2' );
wp_enqueue_script('jquery-masonry', array('jquery'));
}//End add_scripts
add_action('wp_print_scripts', array(&$this,'lart_front_end_scripts'));
Other jquery is loaded like normal, but I keep getting “masonry has no method” in the console and it’s clearly not being loaded because of its absence under network – scripts console.
Help much appreciated.
Edit: I’ve updated my code to use enqueue_script instead of print_script.
function masonry() {
wp_enqueue_script('jquery-masonry');
}//End add_scripts
add_action('wp_enqueue_scripts', array(&$this, 'masonry'));
Still no dice.
Okay, so I made Underscore and Masonry a Dependency of another script and then it worked.
I stopped trying to enqueue add action core scripts and just set it as a dependency for the script that needed it.
Now, I’m not entirely sure if that is how it’s supposed to work, I thought you still had to enqueue add action the script before you could set it as a dependency, the advantage of core scripts was that you just didn’t have to register it.
So without enqueue add action’
wp_enqueue_script('homeJS', get_template_directory_uri() . '/js/home.js', array('jquery','underscore','jquery-masonry') );
Now all of of my required scripts work.
To clarify, only homeJS is being enqueue’ with:
function enqueue_script(){
if(is_admin()) return;
wp_enqueue_script()......
}
Jquery, Masonry and other core scripts have not been enqueued this way.
Just use wp_enqueue_scripts:
Masonry is bundled with and already registered by WordPress.
All you have to do, is to enqueue it: