Showing different sidebar on different pages
To show a different sidebar on different pages, replace the standard call for the sidebar:
<?php get_sidebar(); ?>
with the following code:
<?php include ('sidebar2.php'); ?>
The same can be done to call different headers, i.e. instead of <?php get_header(); ?> use <?php include ('header2.php'); ?>For more information, see Different Sidebars Anyone? on the WordPress codex.
Category: Code Snippets, Tips











But wait, which page do I add/change this code on?!
thanks for this tips! was really useful as i was configuring a website for my client
What next? confuse……….
For the ones who are confused:
1. You create a new page template (check google)
2. In your new page template php, you do these changes mentioned here.
3. Select your new template on the pages you want to have your new sidebar
I think that should answer you
The only problem with this, it’s kinda crazy to create a different template for every sidebar. I did it this way for a while and wound up with a dozen or so extra files in my WP theme folder. It sucked. Better to use some if/then magic in your sidebar or page.php
@cole, well yo uare right cole but if yo do that, that means you basically are adding load time to the site. Shorter the files to load is better.
But on the other hand, not every site is harmed by few lines of code you might add to a file. It depends if it’s worth it
Do you have some example of this “magic” you are talking about?
Nice and interesting topic!
I wished we could have developed the subject a bit more…
Thank you ! I was looking for this
Can someone help me? This didn’t work for me. I want to have a custom sidebar for my about page, and I created a new php file for the about page as well as a new unique php for the sidebar (sidebar2.php)…. but it’s not changing, the main sidebar is still showing up.
help please!
@lily: did you change the page template from the admin panel? Your new about page should be a new template. Here are steps:
1. Create a new page template (something like about-page.php and check google on how to)
2. Create new sidebar php for that page (as explained above)
3. Go to admin and edit the about page and change page template to be your new about-page template.
That should do it. If not, you might be missing something in these steps.
For a codeless approach, you might try my <a href=http://www.mlynn.org/graceful-sidebar-plugin>Graceful Sidebar Plugin</a>. This plugin enables you to customize the content of your sidebar for each page or post. Simply create two custom fields in your page or post called “graceful_title” and “graceful_content” and drag the widget to your theme’s sidebar.
Enjoy!