1
votes

I'm trying to have multiple styles on my website. To me, this code should work but if anyone could tell me why it is not that would be great!

if (is_front_page()) {
        wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/stylee.css');
} else{
        wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/css/temp.css');
}

This is located in my functions.php.

1
This is located in my functions.php - Stephen

1 Answers

0
votes

is_front_page() will always return false when is used in functions.php like that. You have to create a hook using wp to get it working. The reason why is not working is because when functions.php boots Wordpress doesn't know about the content of the query, so it won't know the type of the page you are one. Try this:

add_action( 'wp', 'check_is_front_page' );
function check_is_front_page() {
   if(is_front_page()){
      wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/stylee.css');
  }else{
      wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/css/temp.css');
  }
}

You can read about this specific hook here.

You can read more about hooks and how they work here.