• I’m using the jquery.masonry.js script to display thumbnails in a brick style grid (see here for an explanation https://masonry.desandro.com/).

    I’m running into a bit of a strange problem. When the page first loads the thumbnails aren’t displayed properly, however when the page is refreshed everything works as expected.

    If I clear the browser cache and reload it goes back to not working, and so on.

    This makes me think that I’m doing something wrong with the way I’m enqueueing my js. This is what I have in my functions file, don’t see too much wrong with it.

    if (!is_admin()) {
    	wp_deregister_script( 'jquery' );
    	wp_register_script( 'jquery', get_bloginfo('stylesheet_directory').'/libs/jquery-1.6.1.min.js' );
    	wp_enqueue_script( 'jquery' );
    	wp_enqueue_script( 'jquery_ui', get_bloginfo('stylesheet_directory').'/libs/jquery-ui.custom.min.js' );
    	wp_enqueue_script( 'jquery_masonry', get_bloginfo('stylesheet_directory').'/libs/jquery.masonry.min.js' );
    
    }

    I’d be interested to know if this problem can be replicated by other users and if so if anyone has a clue what might be wrong?

    The URL is: https://new.scratchpictures.co.uk/?page_id=17

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You wrap those in a function then execute via add_action ('wp_enqueue_scripts', 'my_load_scripts');

    So:

    function my_load_scripts() {
    if (!is_admin()) {
    	wp_deregister_script( 'jquery' );
    	wp_register_script( 'jquery', get_bloginfo('stylesheet_directory').'/libs/jquery-1.6.1.min.js' );
    	wp_enqueue_script( 'jquery' );
    	wp_enqueue_script( 'jquery_ui', get_bloginfo('stylesheet_directory').'/libs/jquery-ui.custom.min.js' );
    	wp_enqueue_script( 'jquery_masonry', get_bloginfo('stylesheet_directory').'/libs/jquery.masonry.min.js' );
    
    }
    }
    add_action ('wp_enqueue_scripts', 'my_load_scripts');

    See if that helps

    Also, I think wp_enqueue_script('jquery'); loads the version of jquery bundled with WordPress , so you are loading it twice.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘jQuery execution problem’ is closed to new replies.