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.
Comments
10 Responses to “Easily Add Custom Header, Footer, or Sidebar for Each Category”Share Your Opinions
Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!
Please make sure that you have read our Comment Policy.











Is there a way to change the sidebar/header on a single post, depending on the post’s category?
Yes it is possible. You will have to use this tutorial about creating custom single post templates in WordPress.
I recently purchased a WP Book and designed a wesbsite using WP and this is very useful. Thanks!
ohhh this is what i have been looking for!!! Have been trying to figure out how to display a section with advertisements related to categories in wordpress and here it is!!!
thank you HEAPS!
Thank you so much for this post. This really bailed me out of big trouble. I looked for plugins to do this job for me but couldn’t find any. I was so glad to find the solution on this post.
Now I can create different headers for different categories.
Thanks again and keep up the good work.
hi, thanks for a a great tutorial, this is just what i was looking for. i now have a custom sidebar for one of my categories, and as I kept the dynamic sidebar code I thought I would be able to add widgets to it. It however does not show up in the widget editor. how do i get it so I can add widgets to my category specific sidebar?
Follow this tutorial.
Does this trick do the same with pages?
Tnx !
For pages, you just use the custom page templates.
WPBeginner does it again! I was looking for ages for a solution to add a different sidebar to different categories, and this worked a treat. Thanks