How to add custom header,footer and sidebar on different category in wordpress

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

How to add custom header,footer and sidebar on different category in wordpress

How to add custom header,footer and sidebar on different category in wordpress

Ohh..!! This is amazing article that helps you how to add custom header,footer and sidebar on different category in wordpress.

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

1
2
3
4
5
<?php if (is_category('Blog')) {
get_header('blog');
} else {
get_header();
} ?>

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

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

1
2
3
4
5
<?php if (is_category('Blog')) {
get_sidebar('blog');
} else {
get_sidebar();
} ?>

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

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

1
2
3
4
5
<?php if (is_category('Blog')) {
get_footer('blog');
} else {
get_footer();
} ?>

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

Add comment


 

Pin It on Pinterest

Share This