Austin SEO Company | TastyPlacement
Call Now: 512-535-2492
  • Austin SEO
    • TastyPlacement in the Press
    • Team
    • Our Markets
      • SEO Dallas TX
      • SEO Houston TX
      • SEO San Antonio TX
  • Blog | Tutorials
  • Services
    • Industry Specific
      • HVAC SEO & Marketing
    • Local
      • Local Directory Submission
      • Google Maps Ranking Consulting
    • Mobile
      • Mobile SEO and Digital Marketing
      • Mobile Website Design
    • Web Development
      • Ecommerce Web Dev
      • WordPress Development
    • Tracking & Analytics
      • Analytics and Monitoring
      • Web Performance Call Tracking
      • SEO Article Tracker Software
    • PPC Management
    • WordPress SEO Service
    • Infographic Development
    • Social Media Marketing
  • Case Studies & Portfolios
    • Infographic Portfolio
    • SEO Portfolio
    • SEO Testimonials
    • Design Portfolio
  • Contact TastyPlacement
    • Job: Local Digital Marketing Specialist
    • Job: Social Media Manager Trainee
    • Job: Search Marketing Trainee
    • Job: SEO and Internet Marketing Sales
    • Privacy Policy & Terms of Use
    • Google Adwords Disclosure

How to Add a Sidebar to Your WordPress Theme

How to Add a Sidebar to Your WordPress Theme

Most simple WordPress templates/themes generally employ a single sidebar. But, in keeping with WordPress’ open architecture, you can easily add a second (or 3rd or 4th) sidebar to your site’s theme. And, you aren’t restricted to using your sidebar in the typical sidebar area–you can put your new sidebar in a header, a footer, or any other area in your template. Additional sidebars let you place any WordPress Widget (such as Recent Posts, Pages, Links/Blogroll, Calendar, Tag Cloud, as well as any custom widgets) into new areas of your WordPress template. This technique is especially powerful when combined with custom WordPress page templates–with additional sidebars, we can have custom sidebars for each of our custom page templates. This is the approach we’ll teach you in this tutorial.

Laying the Groundwork for Your New Sidebar

So what we’ll do in this tutorial is to add a second sidebar to one of our custom template pages in our WordPress theme. We have a custom homepage in our template where we want to include a robust call to action to our website visitors rather than a Category list which is more appropriate for blog readers. The screenshot below shows the default “Sidebar 1″ sidebar from our simple template, and we’ll add a second sidebar called “Homepage Sidebar”.

Add WordPress Sidebars

Let’s first take a 10,000 foot view, we are going to employ the following steps to add our sidebar:

  • We are going to register our sidebar within the template by making an entry in the template’s functions.php file.
  • We are going to create a separate, custom sidebar file called sidebar-homepage.php.
  • We are going to include a reference to our custom sidebar-homepage.php file in our custom page template.

That’s it! With these three steps, we’ll have a 2nd sidebar that will display on our custom homepage. With the same technique, we could create additional sidebar areas, the steps would be the same.

Step 1: Registering the Additional Sidebar Within the WordPress Template

First step: we start by registering our sidebar within the template’s functions.php file. 99% of all WordPress templates/themes have a functions.php file. If your theme doesn’t have one, simply create a file in a text editor (we like Notepad++ in the Windows environment and TextMate in the Apple environment). If you don’t know how to find your theme files, you’ll find them in your web host in the following directory: www.yoursite.com/wp-content/themes/yourtheme/.

You’ll want to begin by finding any existing “register_sidebar” entries in your functions.php file. Ours had the following existing sidebar definition for our single default sidebar:

if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}

To register our second sidebar, we simply add the following code to the functions.php file:

if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Sidebar',
'id' => 'homepage-sidebar',
'description' => 'Appears as the sidebar on the custom homepage',
'before_widget' => '<div style="height: 280px"></div><li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}

So what did we just do?

  • We told our WordPress installation, “we are adding a second sidebar area that we’ll use in our theme”
  • The sidebar’s name is “Homepage Sidebar”
  • The ID of the sidebar (we’ll refer to that ID later) is “homepage-sidebar”; you can choose “footer-sidebar”, “second-sidebar” or anything you want
  • We added the description “Appears as the sidebar on the custom homepage” that will display just under the sidebar’s title.

If you upload your new functions.php file to your WordPress installation, you should see your new sidebar if you browse from your WordPress dashboard to Appearance, then Widgets. It should look like the following picture. We’ve already added a Text Widget with the title “Contact Us” to ours, but yours will be empty when you first look at it. But, all we have done is create the sidebar so far; we haven’t yet taken the steps to display the sidebar anywhere in our theme, that will come in the next steps.

Add WordPress Sidebar Step 2

If you see your new sidebar in the Widgets area of your WordPress Dashboard, you are ready to move on to the next step.

Step 2: Create an Additional Sidebar File

WordPress themes use a default file called sidebar.php to display sidebars on pages and posts. But, our goal is to create a second sidebar, we’ll do that with a separate file called sidebar-homepage.php.

Again, we’ll open our text editor and create a file and paste in the following code and insert the ID of your new sidebar within the “dynamic_sidebar()” declaration like so:

<div id="sidebar">
   <ul>
      <?php
      if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('homepage-sidebar') ) :
      endif; ?>
   </ul>
</div>

Now, we have to note that our example sidebar file is highly simplified. Most sidebar files have more code–this extra code displays core navigation in the event the sidebar does not have any widgets installed in it–but for the purposes of this tutorial, we have to simplify it. As an alternative, you can simply copy your sidebar.php file and rename it. Don’t forget to include your sidebar ID within the dynamic_sidebar declaration (shown in red in the code example above)–that sidebar ID tells WordPress which sidebar (which we registered in Step 1) to display.

Step 3: Call the Additional Sidebar from Your Theme Files

We’re almost there. Now, all we need to do is call our new sidebar file, sidebar-homepage.php from our template files–keep in mind that our file name must follow this construct: sidebar-_______.php; we’ll see why in a moment. In our example, we’ll call our sidebar file from a custom template page–but you can call your new sidebar from a footer file, header file, or any theme file that displays on your WordPress site.

The function in WordPress that calls sidebars is get_sidebar(). When get_sidebar() is used with no information within the parenthesis, WordPress grabs the default sidebar.php file. But we want to grab our sidebar-homepage.php file, so we put “homepage” in single quotes within the get_sidebar parentheses. This tells WordPress to grab a file called sidebar-homepage.php . The code we want to insert in our template file is the following:

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

What we’ve told WordPress to do is the following: we want to grab a sidebar file, but not the default sidebar, we want a file called sidebar-homepage.php. With this string of code, we’ve successfully grabbed our custom sidebar file.

Our New Sidebar

If you’ve coded your additional sidebar correctly, you can drag Widgets from the WordPress dashboard to your new sidebar and you’ll see the widgets displayed on your WordPress site. Here’s our new sidebar displaying on our homepage, while we display our default sidebar on interior pages and blog posts:

Our New WordPress Sidebar

Other Approaches to Adding Sidebars

Our method is one of many, there are more elegant ways of accomplishing the same result without creating separate template files, but the method outlined here is simple and reliable. Please comment below if you have questions or run into trouble.

 

tutorial, Web Design, WordPress, wordpress templates, wordpress themes

About the Author: Michael David


Michael David is the founder, current CEO, and lead strategist at TastyPlacement, based in Austin, Texas. He is the author of "WordPress 3.0 Search Engine Optimization" with the prestigious IT publisher, Packt Publishing. TastyPlacement performs search marketing campaigns, public relations, search engine optimization, social media consulting and online advertising for companies in a wide range of fields.

37 comments on “How to Add a Sidebar to Your WordPress Theme”

  1. danny says:
    February 8, 2012 at 9:09 pm

    very helpful tutorial!!! thank you so much

    Reply
    • deconia says:
      November 7, 2012 at 3:21 am

      Michael good work……!!!!!

      Reply
  2. sohbet says:
    February 10, 2012 at 4:32 pm

    Thanks! Didn’t know one could do it that way. :)

    Reply
  3. Massoud Asgharzada says:
    March 19, 2012 at 9:05 am

    It was great tutorial. Thank you so much. But in my website, it shows a dot (.) behind the sidebar. I need to remove that but don’t know how to to that. could you please help to solve it?

    Reply
    • Michael David says:
      March 20, 2012 at 6:38 am

      What is the website? Email it to me at michael[at]tastyplacement.com

      Reply
  4. hk says:
    April 4, 2012 at 8:03 pm

    hi there,
    this is working if i stick to adding one more sidebar…as soon as i add an array of sidebars (to get more than one in the footer area) I am seeing the widgets in the WP cms widget area, i can add stuff to it, it is also outputting the widgets in the source code, BUT the content within the widgets is missing – it isn’t being output anywhere…Any ideas would be highly appreciated.

    Reply
  5. Rick A Prentice says:
    May 2, 2012 at 9:17 pm

    From what I understand, this will only take the place of the existing sidebar so you can swop it out on a per page basis. I have a theme with template options: “Full Page”, “Left Sidebar”, “Right Sidebar”. I need to have a “Left and Right” sidebar on the same page. Unless I have misunderstood how this method works, I don’t think it will do that. Or, have I got it wrong?

    Reply
    • Michael David says:
      May 3, 2012 at 6:54 pm

      No, with this method you can add two sidebars to the same page…in your template file, just call both sidebars:
      < ?php get_sidebar('left'); ?>
      < ?php get_sidebar('right'); ?>

      Reply
  6. Marvin says:
    May 2, 2012 at 11:04 pm

    Great tutorial but my new sidebar appears disordered in the botton of my site. do i have to do something in the css styles?

    Reply
    • Michael David says:
      May 3, 2012 at 6:55 pm

      Every template is different, so yes, you might need to make some css adjustments. It’s hard for me to say exactly without studying the template. If you are stuck, you can probably call in a coder for a quick job like that for like 20 bucks on Craigslist or even Elance.

      Reply
  7. sonali says:
    May 29, 2012 at 3:45 am

    It’s helped me lot… thank you so much…… :)

    Reply
  8. mahmud says:
    June 8, 2012 at 11:48 am

    actually i searched here and there for a way out to create a sidebar just beneath the category nav of my theme. your article gave me the basic idea and i did it on my own accord. thanks to pave me the path.

    Reply
  9. Robert says:
    July 23, 2012 at 7:13 am

    Thanks for this badass tutorial! Incredible walk through and I love your “10,000 foot view.” It really helped add four ‘sidebars’ into my footer area.

    Reply
  10. Rehman says:
    July 30, 2012 at 6:06 am

    Nice tutorial!

    Reply
  11. Ken says:
    August 25, 2012 at 8:02 am

    This is absolutely one of the best clearly stated tutorials I’ve come across, except for one issue…and maybe I just don’t get it…

    Appearance==>Editor ==> list of templates on right of page. I see all the templates listed on the right including sidebar.php. Exactly how do I find the folder in which sidebar.php file exists. That is, where do I actually re-create and rename the second (re-named) php file.
    Thanks in advance!

    Reply
    • Ken says:
      August 25, 2012 at 1:04 pm

      Am I correct in the answer to my own question is: Go to CPanel??? wp-content??
      Thx

      Reply
    • Michael David says:
      August 26, 2012 at 7:36 am

      Your template files are found here: yoursite.com/wp-content/themes/YOURTHEME/sidebar.php….for example, our theme stylesheet is in the template folder here: http://www.tastyplacement.com/wp-content/themes/tastykita-child/style.css

      Reply
  12. mehdi says:
    September 4, 2012 at 10:39 am

    i want to add a extra sidebar on the left i have just one on the right how i can do that

    Reply
    • Michael David says:
      September 20, 2012 at 10:21 am

      That’s a bit more work because you need to create a css-based

      area in which to house the new sidebar–and then integrate that new area in to the theme’s architecture. That is pretty advanced–we’ll consider writing a tutorial on that in the future.
      Reply
  13. Willi says:
    September 13, 2012 at 8:17 pm

    Well written tutorial. That helped a bunch. Very generous friendo!
    My peeps live in Fredericksburg… if I gen up some Hill Country clients, I’ll point them to ya!

    Reply
  14. Madeline says:
    September 14, 2012 at 6:32 pm

    Great tutorial! Is there a way to add a sidebar to a one column theme?

    Reply
    • Michael David says:
      September 20, 2012 at 10:20 am

      Wise guy answer: replace the theme. Well, that’s quite a bit of surgery, I think before I did that I would consider upgrading the template to a shiny new one, seriously.

      Reply
  15. Kwadwo says:
    October 7, 2012 at 1:27 pm

    Awesome tutorial… i love it… how do i call this sidebar so it only appears on a certain category and not the homepage? Thanks … Great post

    Reply
    • Michael David says:
      October 16, 2012 at 5:19 pm

      That’s more complicated and you need to use a plug called “Custom Post Template” which you can find on WordPress.org.

      Reply
  16. dave says:
    October 12, 2012 at 9:19 am

    Brilliant tutorial that’s absolutely saved the day

    Reply
  17. Courtney says:
    October 31, 2012 at 10:15 am

    Ah, but what about for a child theme? I think there’s a lot more involved, am I right? In order to add a sidebar, I have to unregister the parent themes? Can you help me out?

    Reply
  18. Courtney says:
    October 31, 2012 at 11:18 am

    Not to worry, I found the solution!

    Reply
  19. manoj says:
    November 5, 2012 at 12:19 pm

    After trying several tuts i ended up here, thanks a lot bud..

    Reply
  20. cat says:
    November 9, 2012 at 3:16 pm

    Such a great tut, thank you so much!

    Mine worked nearly perfectly… apart from the final step, getting the sidebar to show up!

    My site: http://catillest.com/shop/bear-style-t-shirt/ The standard sidebar is still showing, even though this page is set to product template and the product-sidebar is called within that… I’m not sure what I’m missing.

    any ideas anyone? Any help massively appreciated!

    Reply
    • cat says:
      November 9, 2012 at 3:20 pm

      Agh! Scrap that, all in the naming ‘sidebar-xxxx.php’

      Reply
  21. abouttec says:
    November 12, 2012 at 10:54 am

    Really very helpful, thanks.

    Reply
  22. Alberto Suárez says:
    November 19, 2012 at 1:42 pm

    Thank you very much for your great tutorial !

    Reply
  23. saif says:
    November 23, 2012 at 1:00 am

    Thnx sir
    I realy like it

    Reply
  24. Louie Garofalo says:
    November 25, 2012 at 1:21 pm

    Thanks for writing this up. Very helpful when I had to do some wordpress template building on the fly.

    Reply
  25. Denis says:
    December 10, 2012 at 5:21 pm

    Hello, I’d need help, how to add another sidebar in the theme OpenDoor. I need another sidebar to the right. This theme http://themeforest.net/item/opendoor-responsive-real-estate-and-car-dealership/full_screen_preview/3417587

    Reply
  26. Colin says:
    December 15, 2012 at 3:23 pm

    Hi all,
    Going crazy here trying to get a sidebar to show up.
    I created a custom page template to have a blog page and modified the home page to stop posts showing up. Thats all working nicely.

    I want to have the blog categories show on the blog page so was planning to put the categories widget on a sidebar created using widgets on pages plugin. Completed the steps for that but no sidebar. Completed the steps here and no sidebar. I dont have the layout options available when creating a page and cant figure out why, is this because of the theme im using?

    I tried using another plugin Page Columnist to create columns but still no sidebar

    Reply
  27. Jerome O'Connor says:
    January 1, 2013 at 1:07 pm

    A very concise and well-written tutorial. I hope you do more.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog and Tutorial Categories

  • Backlink Strategies
  • Infographics
  • Internet Marketing
  • Local Maps and Local Listings
  • Mobile SEO
  • Our Book: SEO for Wordpress
  • PHPLD
  • Portfolio
  • PPC
  • Programming & PHP
  • SEO
  • SEO Power Tools
  • SEO Resources
  • Social Media Marketing
  • Web Design
  • WordPress

Recent Posts and Tutorials

  • New Places for Business Bulk Upload Tool
  • Google Places Update: How to Find Missing Google+ Local Listings
  • New Orleans Pubcon 2013 Epic Dining Guide
  • Infographic: Fonts & Colors That Drive the World’s Top Brands
  • Infographic: Urban Mining
Call: 512.535.2492

Our Core Services

  • Austin SEO
  • Dallas SEO
  • San Antonio SEO
  • Austin PPC Management
  • WordPress SEO Service

Some Rich Snippets…

TastyPlacement

3910 S I H 35 Ste 302
Austin, Texas 78704-7424 USA
Office: (512) 535-2492

Scan Me

QR Code

Let’s Be Super Best Friends:

  • TastyPlacement on LinkedIn
  • TastyPlacement on Facebook
  • TastyPlacement on Twitter

TastyPlacement