I'm using sub directories for my WordPress multisite, posts are controlled with single.php. How can instruct single.php to use a different header and footer file for the site in the sub directory?

I tried using get_current_blog_id but that didn't seem to work. For example:

$current_blog = get_current_blog_id();

if ($current_blog == 2) {
    get_template_part('header', 'blog2');
} else {


I was able to use in_category so this is my solution for now:

if (in_category('News')) {
        get_template_part('header', 'blog2');
    } else {

I'm surprised get_current_blog_id() didn't work, since that's probably the best way to approach it. Always try doing a var_dump( $current_blog ) to make sure you're testing for what you need. Edit (19 Aug 2015): Also, triple check that you know which header you're expecting to see and that you're making the change you want in the right header file.

Alternately, consider making a child theme and replacing the header that way. That may be more maintainable over the long run, particularly if you plan on using unique headers for other sites.

Also, you can use get_header( 'blog2' ) instead of get_template_part( 'header', 'blog2' ). Same result but the first way's a bit cleaner.

  • I was surprised that get_current_blog_id() didn't work as well. I did a var_dump on $current_blog and the output was int(2). Thank you for the suggestion regarding calling the template part as well. I'm going to use that moving forward.
    – brandozz
    Aug 19 '15 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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