WordPress Enqueue for homepage only, functions.php, wp-framework

First, if you want to target the site Front Page, you need to use is_front_page(). The is_home() conditional returns true when the blog posts index is displayed, which may or may not be on the site Front Page.

Second, you need to hook your function into an appropriate hook, which it appears in this case is wp_enqueue_scripts.

(Also: what is get_theme_part()? Is it a custom function in WP Framework?)

For example, you can do this in functions.php:

function mytheme_enqueue_front_page_scripts() {
    if( is_front_page() )
    {
        wp_enqueue_script( 'homestuff', get_theme_part( THEME_JS . '/home.js' ), array( 'jquery' ), null, true );
        wp_enqueue_script( 'jquerycolor', get_theme_part( THEME_JS . '/jquery.color.js' ), array( 'jquery' ), null, true );
    }
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_front_page_scripts' );

Leave a Comment