WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
  • Deals
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Themes» Easily Add Custom Header, Footer, or Sidebar for Each Category

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

Last updated on June 21st, 2012 by Editorial Staff
14 Shares
Share
Tweet
Share
Pin
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')) {
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.

14 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

23 Comments

Leave a Reply
  1. Dave B says:
    Dec 21, 2017 at 12:45 pm

    I’ve tried to implement a different footer on the static home page with the following code, but it doesn’t work….
    Can you help please?

    }

    Reply
  2. Johann says:
    Apr 12, 2017 at 10:35 am

    Hi all,

    This is a great trick, but one of my client asked if we can can adapt this to WooCommerce?
    I tried but unsuccessful…

    Can you tell me how would you implement this to WooCommerce archive-product.php template?

    Reply
  3. Gabrielle says:
    Aug 23, 2015 at 12:14 pm

    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

    Reply
  4. John says:
    Feb 10, 2015 at 4:18 pm

    But how do I do this for each category?

    Reply
  5. Ivan Jaquez says:
    Feb 1, 2014 at 1:03 pm

    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 ;)

    Reply
  6. Carol Dunlop says:
    Dec 13, 2013 at 8:55 am

    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.

    Reply
  7. Stuart Mackey says:
    Sep 27, 2013 at 6:23 pm

    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.

    Reply
  8. hamed.oveysi says:
    Sep 3, 2011 at 8:03 am

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

    Reply
  9. David says:
    Jan 10, 2011 at 11:37 pm

    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.

    Reply
    • Editorial Staff says:
      Jan 18, 2011 at 9:47 am

      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.

      Reply
  10. Mike says:
    Dec 29, 2010 at 9:57 am

    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.

    Reply
  11. DaveK says:
    May 30, 2010 at 7:09 am

    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

    Reply
  12. Ljuboja says:
    Feb 12, 2010 at 2:30 pm

    Does this trick do the same with pages?
    Tnx !

    Reply
    • Editorial Staff says:
      Feb 13, 2010 at 12:00 am

      For pages, you just use the custom page templates.

      Reply
      • dains says:
        Apr 14, 2011 at 7:42 am

        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 (http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page) 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.

        Great

        Reply
  13. sven says:
    Nov 8, 2009 at 7:33 am

    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?

    Reply
    • Editorial Staff says:
      Nov 9, 2009 at 1:26 pm

      Follow this tutorial.

      Reply
  14. shravan says:
    Nov 8, 2009 at 5:28 am

    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.

    Reply
  15. Delighted Programer says:
    Oct 12, 2009 at 4:03 am

    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!

    Reply
    • Wellwisher007 says:
      Jan 13, 2012 at 12:43 am

      improve the spelling of programer to programmer

      Reply
  16. wrerm says:
    Oct 12, 2009 at 1:07 am

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

    Reply
  17. Jason Pelker says:
    Oct 11, 2009 at 4:34 pm

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

    Reply
    • Editorial Staff says:
      Oct 11, 2009 at 4:49 pm

      Yes it is possible. You will have to use this tutorial about creating custom single post templates in WordPress.

      Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
WPForms Logo
WPForms
Drag & Drop WordPress Form Builder Plugin. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 25 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2019 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2019)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2019)
    • SiteGround Reviews from 1032 Users & Our Experts (2019)
    • Bluehost Review from Real Users + Performance Stats (2019)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Start a Podcast with WordPress (Step by Step)
    • How to Choose the Best Domain Name (8 Tips and Tools)
    • How to Setup a Professional Email Address with Google Apps and Gmail
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2019 – Step by Step Guide
Deals & Coupons (view all)
Dreamhost
DreamHost Coupon
Get 40% OFF on DreamHost and get a Free Domain.
Elegant Themes
Elegant Themes Deal
Get all 87 amazingly beautiful WordPress themes by Elegant Themes for only $69. That is like $0.79 per theme!
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • Awesome Motive

Copyright © 2009 - 2019 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

WordPress hosting by HostGator | WordPress CDN by MaxCDN | WordPress Security by Sucuri.