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