Skip to content

Multiple Sidebars the Right Way

Multiple sidebars are becoming increasingly popular with specific sidebars being displayed only on specific pages or posts. How do they do it? Originally it’d be an if (ie if is homepage) and then include a PHP file, but WordPress has a better way. A built in better way. In this post we’ll learn how to add multiple sidebars the right way.

The old, rubbishy way

Back in the day, you’d have something like this:

<?php include (TEMPLATEPATH . '/single-sidebar.php'; ?>

Which isn’t too pretty. Because WordPress has a better way of doing things. Which is using the get_sidebar function that is normally used to get the sidebar.

The new, brilliant way

It’s really as simple as renaming your new fancy sidebar sidebar-something.php and then you can use the get_sidebar function like so:

<?php get_sidebar('something'); ?>

And that’s all there is to it. I would write more, but that’s essentially it. So I won’t. Enjoy your new found knowledge!

Yay! 🎉 You made it to the end of the article!
Alex Denning
Share:

8 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Amor
May 4, 2010 4:34 pm

I've been using

<?php include ('sidebar-single.php'); ?>
<?php include ('sidebar-page.php'); ?>

I didn't know I could use

<?php get_sidebar('single'); ?>
<?php get_sidebar('page'); ?>

learned something new again. Thanks Alex!. 🙂

Doug C.
April 4, 2010 3:19 am

I don’t get it. So you got “” … then what?

Say I make a widget that I only want to display on certain pages. How would I add that using this “get sidebar” code?

Now that would be an interesting and useful post.

Best Practices for Creating Unique Blog Posts | WPShout.com
January 27, 2010 5:36 pm

[…] the sidebar, but instead display a different sidebar. That’s easy if you do multiple sidebars the right way, which, of course, has the following […]

Theo
January 16, 2010 5:11 pm

Truly brilliant !
Thanks

Rebecca
January 12, 2010 4:06 am

Thanks, just the simple instructions I was looking for!

Cracks
December 16, 2009 8:31 am

So why exactly is the get_sidebar version is better?

Is it just a “pretty” factor, or is it less load heavy? Please explain.

Sara
November 18, 2009 3:17 pm

Nice to know about, thanks!

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!