Masonry imagesLoaded javascript error
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.
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.
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'
});
});
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.
Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.