Site icon CodeRevolution Knowledge Base

How to: Get a particular header, footer, or sidebar – CodeRevolution

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

Exit mobile version