Update: I cant enqueue any core scripts. Masonry wont load with enqueue handle, WordPress 3.6.

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:

Read More
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.

Related posts

3 comments

  1. 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.

  2. wp_print_scripts should not be used to enqueue styles or scripts on the front page. Use wp_enqueue_scripts instead.

    Just use wp_enqueue_scripts:

    add_action( 'wp_enqueue_scripts', 'myScripts');
    function myScripts (){
        wp_enqueue_script('jquery', '1.10.2' );
        wp_enqueue_script('jquery-masonry', array('jquery'));
    }
    
  3. Masonry is bundled with and already registered by WordPress.

    All you have to do, is to enqueue it:

    function lart_front_end_scripts() {
        wp_enqueue_script('jquery-masonry');
    } // function lart_front_end_scripts
    add_action('wp_enqueue_scripts', array($this, 'lart_front_end_scripts'));
    

Comments are closed.