In functions.php I want to enqueue scripts based on what page I’m viewing: home page, single page, etc.
It all seems to work except when I go on a blog category.
I tried the following (in functions.php):
is_front_page() -> works
is_page() -> works
is_single() -> works
is_category() -> NOPE.
function load_ngof_files() {
wp_enqueue_style( 'ngof_common', get_template_directory_uri() . '/assets/css/com.css');
if (is_front_page()) {
// echo "front page";
wp_enqueue_style( 'ngof_front', get_template_directory_uri() . '/assets/css/front.css');
} elseif (is_category()) {
echo "category";
wp_enqueue_style( 'ngof_cat', get_template_directory_uri() . '/assets/css/cat.css');
} elseif (is_page()) {
echo "page";
} elseif (is_single()) {
// Blog posts index page
echo "single";
}
}
add_action('init', 'load_ngof_files' );
Any ideas why? category.php is called correctly.