Skip to main content
edited title
Link
vancoder
  • 7.9k
  • 27
  • 35

Proper Way to EncueueEnqueue CSS for Front Page - template_redirect in functions.php?

Source Link
MikeiLL
  • 579
  • 1
  • 8
  • 21

Proper Way to Encueue CSS for Front Page - template_redirect in functions.php?

I want to load some specific css to change color of body element of front/home page of WP. Within my themes function file, the following code seems to work, but can someone please tell me if it is "proper"?

//Adding and Encuing styles for Front Page
add_action( 'template_redirect', 'front_page_design' );

function front_page_design(){
    if ( is_front_page() || is_home()) {
        add_action('wp_enqueue_scripts', 'enqueue_index_styles');
        function enqueue_index_styles() {
        wp_register_style( 'home_page_style', get_stylesheet_directory_uri() . '/index-style.css' );
        wp_enqueue_style( 'home_page_style' );
        }
    }
}

I had come across a blog by Mark Jaquith saying that template_include is for including, which is what I'm doing, right?