1

After enqueing scripts as per WP codex and WP Beginner tutorial the site has a Javascript error: Uncaught ReferenceError: imagesLoaded is not defined

Many others also have this problem.

Link: http://www.wpbeginner.com/wp-themes/how-to-use-masonry-to-add-pinterest-style-post-grid-in-wordpress/

  • 1
    It is not nice to just point to a problem/link. Please paste your code if possible and explain the problem clearly. – sri Jun 17 '14 at 10:34
  • check the order of js files loaded on site source code. – Sisir Jun 17 '14 at 10:37
2

Followed the same article and ran into the same issue; the author (Josh Pollock) posted a followup on his blog.

Essentially from WP 3.9, Masonry is there for you to use so all you need in functions.php is:

add_action( 'wp_enqueue_scripts', 'slug_masonry' );
function slug_masonry( ) {

    wp_enqueue_script('masonry'); // note this is not jQuery

}

and then initialize:

//set the container that Masonry will be inside of in a var
var container = document.querySelector('#masonry-loop');
//create empty var msnry
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
    msnry = new Masonry( container, {
        itemSelector: '.post'
    });
});
0

If you used code from above link then replace wp_enqueue_script('masonry') with wp_enqueue_script('jquery-masonry'). Try it and let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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