DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Since WordPress 2.7, it is easier to choose which header, footer or sidebar file you want to include on your theme. In this recipe, I’ll show you how to do.

The following code will check if the reader is on the “WordPress” category. If yes, header-wordpress.php will be inclued, otherwise the default header will be used:

<?php if is_category('WordPress') { 
    get_header('wordpress');
} else { 
    get_header();
} ?>

You can also use that new functionality with footers and sidebars:

<?php get_footer('myfooter'); ?>

will include footer-myfooter.php

<?php get_sidebar('mysidebar'); ?>

will include sidebar-mysidebar.php

Leave a Comment

Your email address will not be published. Required fields are marked *