WordPress.org

Forums

jQuery execution problem (3 posts)

  1. Lee Bolton
    Member
    Posted 3 years ago #

    I'm using the jquery.masonry.js script to display thumbnails in a brick style grid (see here for an explanation http://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: http://new.scratchpictures.co.uk/?page_id=17

    Thanks in advance.

  2. Michael Bishop

    Posted 3 years ago #

    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

  3. Michael Bishop

    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic