jQuery(document).ready(function($) { var $sunshinemasonrygallerycontainer = $('#sunshine-gallery-list ul'); $sunshinemasonrygallerycontainer.imagesLoaded( function() { if ( $sunshinemasonrygallerycontainer ) { $sunshinemasonrygallerycontainer.masonry({ itemSelector: '.sunshine-gallery-thumbnail', columnWidth: '.sunshine-gallery-thumbnail', percentPosition: true }); } }); });