Title: WordPress does not load scripts on homepage
Last modified: July 29, 2020

---

# WordPress does not load scripts on homepage

 *  [vincent789](https://wordpress.org/support/users/vincent789/)
 * (@vincent789)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/wordpress-does-not-load-scripts-on-homepage/)
 * Hi everybody,
 * I’ve got an issue regarding to scripts loaded with WordPress functions.php…
    
   Two scripts (masonry and imagesloaded) don’t load on homepage, whatever I do,
   but they load everywhere else….
 * In my functions.php, I’ve got this :
 *     ```
       function glasgow_scripts() {
   
       	wp_enqueue_script( 'jquery' );
   
       	wp_enqueue_script( 'masonry', get_template_directory_uri() . '/js/masonry.pkgd.min.js', array(), _S_VERSION, true );
   
       	wp_enqueue_script( 'imagesloaded', get_template_directory_uri() . '/js/imagesloaded.pkgd.min.js', array(), _S_VERSION, true );
   
       	wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array(), false );
   
       	wp_enqueue_style( 'glasgow-style', get_stylesheet_uri() );
   
       	wp_enqueue_script( 'navigation', get_template_directory_uri() . '/js/navigation.js', array(), true );
   
       	wp_enqueue_script( 'glasgow-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
   
       	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
       		wp_enqueue_script( 'comment-reply' );
       	}
       }
       add_action( 'wp_enqueue_scripts', 'glasgow_scripts' );
       ```
   
 * and also this (and although I fear it could create a mistake, it works really
   well on other sites)…
 *     ```
       function three_scripts() {
       	if (is_home()) {
       		wp_enqueue_script( 'three-init', get_template_directory_uri() . '/js/three-init.js', array(), false );
       		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
       			wp_enqueue_script( 'comment-reply' );
       		}
       	}		
       }
       add_action( 'wp_enqueue_scripts', 'three_scripts' );
   
       function add_type_attribute($tag, $handle, $src) {
       	    // if not your script, do nothing and return original $tag
       	    if ( 'three-init' !== $handle ) {
       	        return $tag;
       	    }
       	    // change the script tag by adding type="module" and return it.
       	    $tag = '<script type="module" src="' . esc_url( $src ) . '"></script>';
       	    return $tag;
       }
       add_filter('script_loader_tag', 'add_type_attribute' , 10, 3);
       ```
   
 * As you’ll see, masonry and imagesloaded aren’t loaded, but script.js is… that
   makes no sense to me. Then I’ve got the “imagesloaded is not a function” error,
   what seems to be logical as it’s not loads on homepage.
 * Does someone has a clue ?
 * Thanks a lot everybody !!! 🙂
    -  This topic was modified 5 years, 10 months ago by [vincent789](https://wordpress.org/support/users/vincent789/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwordpress-does-not-load-scripts-on-homepage%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/wordpress-does-not-load-scripts-on-homepage/#post-13186824)
 * “…is not a function” means there is a syntax error somewhere. I don’t see it 
   in your posted code, but it’s reason enough for enqueuing to not work as expected.
 * BTW, all scripts which depend on another module, like masonry is dependent upon
   jQuery, should have the dependencies specified when enqueuing. For example:
    `
   wp_enqueue_script( 'masonry', get_template_directory_uri() . '/js/masonry.pkgd.
   min.js', array('jquery'), _S_VERSION, true );`
 * When you do this, you don’t really need to enqueue “jquery”, though there is 
   no harm in doing so.

Viewing 1 replies (of 1 total)

The topic ‘WordPress does not load scripts on homepage’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/wordpress-does-not-load-scripts-on-homepage/#post-13186824)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
