I'm trying to add masonry sript to my site, but wp_enqueue_script('jquery-masonry'); is not adding the script.

Instead I have to use:

wp_register_script('jquery_masonry', includes_url(). '/js/jquery/jquery.masonry.min.js', 'jquery');

Why is that?

  • I took it because the answer was not helpful at all, sorry
    – iEmanuele
    Aug 20, 2013 at 17:42
  • @G.M. even if I'm not directly involved, I've tried the code as above and I can get it to work only with wp_register_script in wp_enqueue_scripts hook. this issue is very interesting.
    – iEmanuele
    Aug 20, 2013 at 18:14
  • I deleted my previous comment because I was not understand the question: my english is poor. Sorry, my bad.
    – gmazzap
    Aug 20, 2013 at 18:23
  • wp_enqueue_script('jquery-masonry') works fine for me. You are certain it is not being added? You are not looking at a cached page somehow?
    – vancoder
    Aug 20, 2013 at 18:31

2 Answers 2


jQuery's Masonry is bundled with WordPress. All you should need is wp_enqueue_script('jquery-masonry'); but note that the "slug" is jquery-masonry, not jquery_masonry. And be sure your are enqueueing on the wp_enqueue_scripts hook or later.

function enqueue_masonry() {

I'd guess that your problem has something to do with when you register/enqueue because loading core scripts is pretty straightforward.

If that doesn't work, something is wrong with your site. A plugin or a theme is deregistering, perhaps. Without more information it is going to be hard to say what.

  • I'm not sure this answers his question, which is why does wp_enqueue_script('jquery-masonry') not work for him.
    – vancoder
    Aug 20, 2013 at 18:33
  • @vancoder wp_enqueue_script('jquery_masonry') don't work for him. s_ha_dum says: but note that the "slug" is 'jquery-masonry', not 'jquery_masonry'
    – gmazzap
    Aug 20, 2013 at 18:36
  • @vancoder : see the edit. I am guessing about why it doesn't work, which is about all I can do with the information provided. Those are the only two things I can think that might go wrong, short of server level stuff.
    – s_ha_dum
    Aug 20, 2013 at 18:37
  • 1
    @G.M. You mis-read the question.
    – vancoder
    Aug 20, 2013 at 18:40
  • @vancoder I think you mis-read the code in the question
    – gmazzap
    Aug 20, 2013 at 19:03

s_ha_dum is correct, you don't need to enqueue it yourself.

That being said, the reason your script is not working is because your dependancy variable is not an array. Your code should read:

wp_register_script('jquery_masonry', includes_url(). '/js/jquery/jquery.masonry.min.js', array( 'jquery' ) );

Way down deep in the WP_Dependancies class, if the value passes is not an array, it sets it to be a blank array, therefore making it have no dependancies. (see wp_includes/class.wp_dependancies.php line 251 as of WP 3.6, if interested)

So what I assume is happening, is it's loading in the Masonry script BEFORE jQuery is loaded in, therefore causing it to do nothing.

That being said, use s_ha_dum's response, as it's already registered in WordPress, and waiting to be en-queued.

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.