Multiple WordPress Sidebars with get_sidebar()

Post by 
John Crenshaw
Published 
October 16, 2014

In this article I show you how to use the get_sidebar() function to call multiple sidebars (as many as you want) in your WordPress theme.

WordPress Multiple Sidebars
Example of using multiple sidebars in WordPress

If you've been theming WordPress for a bit you may have come across the need for multiple sidebars, but you may have also realized that the default method of including a sidebar, using the get_sidebar() function, only allows you to include a single sidebar named sidebar.php (without using parameters). There's one obvious way to include a sidebar and that's by using a standard php include like so:

1
include('TEMPLATEPATH . '/right-sidebar.php';

This method works, but in the interest of keeping our code readable and simplifying the inclusion of multiple sidebars, there's an easier way to do this and it's incredibly simple.

Including sidebar-left.php and sidebar-right.php using get_sidebar

Let's say we've got two sidebars, right and left, and we'll name the files sidebar-right.php and sidebar-left.php respectively. To include those files, all we have to do is use the get_sidebar function but add parameters to each function call to tell WordPress which sidebar we want included where.

To include the file "sidebar-right.php" we'll use:

1
get_sidebar('right');

And to include our other sidebar, "sidebar-left.php" we'll use:

1
get_sidebar('left');

Likewise, if we want to include a third sidebar, sidebar-right-2.php for example, we'll use:

1
get_sidebar('right-2');

Syntax of get_sidebar()

It's that simple. The key to remember here is that, as commentator Rakeshkumar Mehta points out, the get_sidebar function prepends "sidebar- to the argument you feed it, so all your sidebar files should start with "sidebar-". For example, to include a file named sidebar-newsidebar.php, use get_sidebar('newsidebar'), or to include a file named sidebar-my_right_sidebar.php, use get_sidebar('my_right_sidebar').

Never miss
an update

We never share your info. View our Privacy Policy
Almost there. Follow these 2 steps to complete your subscription:

1. Click the link in the confirmation email we just sent you

2. Add [email protected] to your address book

Thanks!
Oops! Something went wrong while submitting the form.
THere's More

Post you might also like

All Posts
Analytics
Oct
17
//
2020

Causes & Solutions to Website Traffic Drops After a Redesign

New websites are supposed to outperform the old one, but that doesn't always happen.
Strategy
Oct
15
//
2020

This Famous Ad Exec Talks About a Big Brand Who's Existence Just Doesn't Make Sense

The irrational product that kicked off a $4 billion brand
Strategy
Oct
12
//
2020

How to Gain Market Share

Find out what it takes to grow.
Strategy
Jul
15
//
2020

Marketing Idea 0001: Target the Larger Audience

Sometimes customers that want to rent your product are actually better candidates to buy it.
Paid Media
Jun
12
//
2020

PPC vs CPC: What's the Difference

They aren't the same thing, but they're pretty closely related