0

Since I have different Google Ad Manager codes that need to load in the of different content types, I created separate headers for each type and put this code snippet in index.php to load them accordingly:

if ( is_front_page() ) { 
    get_header('home') ;
}
elseif ( !is_front_page() AND is_page() ) {
    get_header('page') ;
}
elseif ( is_single() ) {
    get_header('article') ;
}
elseif ( is_category() ) {
    get_header('category') ;
}
else {
    get_header() ;
}

All of them work great - except for the category. It isn't loading. It just loads the default header.

What am I doing wrong?

Any help is much appreciated!

Cynthia
  • 5,273
  • 13
  • 42
  • 71

1 Answers1

1

The short answer would be to try and use is_archive() instead of is_category(). If that doesn't work, you may need to dump your global $wp_query variable and see what query types are being returned on that particular url.

In that same vein, you may consider using is_singular() instead of is_single(), because is_single is limited to Posts.

One more point to consider is using && instead of AND (they're synonymous other than precedence. Take a look at this answer for a bit more in-depth on it)

Lastly, if you're only loading in a separate Google Ad Manager code, I'm not sure you need to maintain x number of header files. Have you considered dropping in the script codes into your functions.php file and loading them on the wp_enqueue_scripts or wp_head hooks?

instead of maintaining separate headers like this:

if( is_front_page() ){
    get_header( 'home' );
} else if( is_page() ){
    get_header( 'page' );
} else if( is_singular() ){
    get_header( 'article' );
} else if( is_archive() ){
    get_header( 'category' );
} else {
    get_header();
}

You could drop those scripts straight in based on the same is_ functions using something like this:

add_action( 'wp_head', 'load_ad_manager_scripts' );
function load_ad_manager_scripts(){
    if( is_front_page() ){
        echo '<script>// Home Ad Manage Code</script>';
    } else if( is_page() ){
        echo '<script>// Page Ad Manage Code</script>';
    } else if( is_singular() ){
        echo '<script>// Single Manage Code</script>';
    } else if( is_archive() ){
        echo '<script>// Archive Manage Code</script>';
    } else {
        echo '<script>// Generic Manage Code</script>';
    }
}
Xhynk
  • 13,513
  • 8
  • 32
  • 69