Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to replace my:

    if(is_home())
    {
        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 );
    };

Which is currently in header.php, by putting it in a functions.php file instead. Trying to tidy everything up on a sprawling client's site. I'm using wp-framework and ideally would stick this inside the enqueue_assets function in the main parent_theme class. Although this isn't really a wp-framework issue, I'd just like to know:

How can I get is_home() to work from a functions file? Is there an alternative, using globals, I need to know about?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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' );
share|improve this answer
    
Chip, you're a star. Thanks. (Yes, get_theme_part is a wp-framework thing. I swear by the new wp-framework release. It's awesome) –  mjjwatson Jul 15 '11 at 13:08
    
Oh, right on then. That function should, per best practice, be prefixed as wpf_get_theme_part() or something similar. But, I looked it up; very nice little function. –  Chip Bennett Jul 15 '11 at 13:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.