In a follow-up to the last tutorial on how to define extra sidebars in WordPress, I am going to show you how to add a different sidebar to each page on your site.

If you have not read the post from last week then I suggest you read the tutorial first. Let’s get started.

1. Add a new page within the WordPress admin.

Navigate to pages > add new and create a new page, for the purposes of this post we will call this blog. Add page title and your content then save the page using publish.

2. Duplicate your sidebar.php.

First you need to duplicate your sidebar.php file and rename it. The new sidebar file should be named in the following format, sidebar-name.php, so for example if you want a new sidebar for your blog page you can name the file, sidebar-blog.php. Next you need to add the following code to your new sidebar file as shown in last weeks tutorial.

3. Duplicate your page.php file.

Next you need to duplicate your page.php file and rename it. Now we need to tell WordPress to use the new page, which can be done in 2 ways. The first method is to rename your file to match your page as defined in the WordPress admin in the first step in the Pages tab. The way that WordPress knows to use this page, is by renaming the theme template to page-pagename.php. So if you have a page defined in admin as blog, then you would rename your theme file as page-blog.php. WordPress will then look for this file and display your page using the this template file.

The second way, is by assigning a template to a WordPress page by the use of a defined template code. In the top of the your page.php file you should see code similar to the following.

The code may differ dependant on your installed theme but will follow the same format. This is mainly for identification and is used for some internal functions within WordPress. Did you notice the line shown below?

* Template Name: Blog

By using this code, you will be able to select the page within the admin using the page attributes tab on within the Pages panel as shown in the following image.

The benefit of using this method is that you can use this template for many pages whereas the earlier method is restricted to one page with a set name.

4. Add your sidebar to your page template.

Open the earlier template file you duplicated from page.php and look for the following code.

Now within the parenthesis add the name of your sidebar as you defined earlier, so if you named your sidebar file “sidebar-blog.php” then you should add the name ‘blog’ within the parenthesis as shown below.

When you navigate to http://www.yoursite.co.uk/blog You should now see a new page with your new sidebar defined. You can now add widgets to your new sidebar under Appearance > Widgets. You can repeat this for every page that you require an alternate sidebar to be shown.

Hope you enjoyed this tutorial and if you have anything to add please leave a comment below.

About this site

Hello and welcome to the home of Mike Chesworth based in St Helens, Merseyside. Office Worker by day, aspiring Web Designer/Photographer by night. I have a slight obsession about Apple and it's products.

Are you new here?

I recently entered my first image into an exhibition and I thought I would share my tips and experience that I learned from my first submission. I even won a special award. This experience only applies to open exhibitions where anybody is allowed to submit.

In order to up my photography skills, I have decided to set myself a weekly photo challenge. Every week I will post a new challenge on a Wednesday, using the hashtag #mcweeklychallenge. There are no prizes for winning, its just a bit of fun and maybe it will help improve your photography as well.

I have always struggled with my weight since I was very young, but as I am getting older, I thought it was about time that I got my weight in order. I have managed to lose 4 and half stone so far and I am often being asked what my secret is.