Wordpress

Easily Add Custom Header, Footer, or Sidebar for Each Category

Did you ever see WordPress blogs that have a separate header for different categories? In this tutorial we will share a simple snippet that you can use to add custom header, footer, or even sidebar for each WordPress category.

To call a particular header, you will need to open your index.php and replace your normal header code with this one:

<?php if (is_category(‘Blogging’)) {
get_header(‘blogging’);
} else {
get_header();
} ?>

This code above is basically telling WordPress that if someone opens the category called “Blogging” then WordPress needs to display a file called header-blogging.php if it exist. If it does not exist, or if the category is not blogging, then WordPress displays the default header file.

To get a separate sidebar for each all you need to do is add the following code:

<?php if (is_category(‘Blogging’)) {
get_sidebar(‘blogging’);
} else {
get_sidebar();
} ?>

The code above will look for sidebar-blogging.php to replace the default footer file if the category is Blogging.

To get a separate footer for each category all you need to do is add the following code:

<?php if (is_category(‘Blogging’)) {
get_footer(‘blogging’);
} else {
get_footer();
} ?>

The code above will look for footer-blogging.php to replace the default footer file if the category is Blogging.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s