wordpress tutorial for add custom header, footer, or sidebar for different categories in WordPress. we have given simple conditinal code which need to use in your theme file.

add custom header to different categories in WordPress

If you want to add the different header for each category then use the following code in your index.php where “get_header()” method is called.

Create the Header-new_category.php file and put your header code in that file as per requirement.

For sidebar use this code:


<?php if (is_category(‘new_category’)) {
get_header(' new_category ');
} else {
get_header();
} ?>

Create the Header-new_category.php file and put your header code in that file as per requirement.

For sidebar use this code:


<?php if (is_category('New_category')) {
get_sidebar('new_category');
} else {
get_sidebar();
} ?>

Create the sidebar-new_category.php file and put your sidebar code in that file as per requirement.

For Footer use this code:


<?php if (is_category('New_category')) {
get_footer('new_category');
} else {
get_footer();
} ?>

 

 

Create the footer-new_category.php file and put your footer code in that file as per requirement.

Written by Purab Kharat

My name is Purab Kharat, Here is my Personal Blog: wpapi.com. Work as an Senior Technical Lead at Smartsourcing Global Pvt Ltd in Princeton, NJ, USA. I contributor of many wordpress plugins and Drupal Modules. I am core developer of Drupal. Connect to on LinkedIn or Follow @purab on Twitter or Follow me on Google+ or Write Mail to purabdk@gmail.com or Chat with me on Skype : purabdk

This article has 2 comments

  1. Hans Ronne Reply

    Wow, Purab, thanks for all the great info on your site.

    “custom header to different categories” is just what I was looking for. I’m good in html old school, but not php and wordpress. Trying to convert my old pages to wordpress blog.
    Boy, everything was so easy with html, but wordpress..sigh!!

    Unbelieable that you need to have the same header for the entire blog, and no functionallity built in to change, that’s a nightmare!

    Fortunately I found you, but…I dont quite get it what to do and exactly what files to create.

    Say I have category 1 and category 2, how do I implement the code?
    and what new files do I create?

    Thanks a lot.

Leave a Comment

Your email address will not be published. Required fields are marked *