Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

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

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
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')) {
} else {
} ?>

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')) {
} else {
} ?>

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')) {
} else {
} ?>

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

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Gabrielle says:

    Hi, what can i do if i want to have custom headers, sidebars and footers to be saved in subfolders, like:
    sidebar-cars in folder sidebars/sidebar-cars.php

  2. John says:

    But how do I do this for each category?

  3. Ivan Jaquez says:

    Hello and thanks for this great article. What about each category linking to an external url and not just the homepage? For example: Dog training category’s header linked to an external site. Thanks in advanced ;)

  4. Carol Dunlop says:

    You must have been reading my mind! I just spoke with a client who wants a different footer on one certain page and this looks like it is going to work perfectly. Thanks for the awesome info.

  5. Stuart Mackey says:

    Thanks! I use categories for my business Site to denote the major “service categories” of video production I offer to my clients. This should allow me to have an intro describing the type of video and its function; marketing, testimonial, etc.

  6. hamed.oveysi says:

    I want a custom header for several category pages. Your code works with one category. How to do it?

  7. David says:

    what if i just want a different sidebar than the home page, in other words all categories would have the same sidebar but the home page would have a different sidebar, also how would I be able to edit the different sidebars in the widgets panel?

    thanks for this post btw easiest one I found so far.

    • Editorial Staff says:

      If you just want a different sidebar on the homepage, use the conditional tag if is_home or is_frontpage (depending on how you are creating a custom homepage), and then include a different sidebar file.

  8. Mike says:

    On a related note – you can create a custom sidebar for each individual page or post using the Graceful Sidebar Plugin. To use this you simply edit your post as normal and specify the sidebar widget title and content in the custom edit fields provided by this plugin.

  9. DaveK says:

    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

  10. Ljuboja says:

    Does this trick do the same with pages?
    Tnx !

    • Editorial Staff says:

      For pages, you just use the custom page templates.

      • dains says:

        Actually, a custom page template is a great place to implement this solution. A built-in WP function to tell it to use a custom header, sidebar or footer? Sign me up.

        Since you’re using conditional tags for this solution (is_category), you should be able to use the ones for pages ( in a custom page template. I am planning a custom front page assigned via the admin section, so I’ll be trying it out with is_front_page instead of is_category.


  11. sven says:

    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?

  12. shravan says:

    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.

  13. Delighted Programer says:

    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!

  14. wrerm says:

    I recently purchased a WP Book and designed a wesbsite using WP and this is very useful. Thanks!

  15. Jason Pelker says:

    Is there a way to change the sidebar/header on a single post, depending on the post’s category?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.