Sunday, February 28, 2010

How to add sidebar (widget) placeholder in Wordpress

I didn't find too many posts on Google about this, so I thought I'm going to help you guys to add sidebar (widget) placeholder in Wordpress; it's really so simple:

1 Register your sidebar

Simply open your template's functions.php (by default it's wp-content/themes/[yourtheme] - where [yourtheme] is the folder name of your theme):

Mine looked like this:
(click in the box to highlight the code for copy)

So I just added before the ?> closing tag the following code:
(click in the box to highlight the code for copy)

As you can see, the only thing I did was to copy one set of codes of the sidebars above and pasted it changing the name from 2 to 3. You can change the before_widget, before_widget, before_title and after_title values to whatever you want; you'll be able to use these values later on when styling your widget.

2 Insert the placeholder into your page

Insert this code into the page you want to see the sidebar on:
(click in the box to highlight the code for copy)

3 Add Widgets to the sidebar

Go to Widgets in your Wordpress admin page and add a widget to your newly created sidebar (in my case it is called 'Sidebar3')

4 Style it!

Just add some id's and classes into your page before the sidebar placeholder and style them in your theme's .css.

And we're done! ;)

Later on I found the post How to Add Widgets to WordPress Theme’s Footer - you may find some important additional information in there.

No comments:

Post a comment

Dear legitimate commenters, please post your comments below. I'd be happy to receive your feedback; helps me a lot improving, or getting reassurance that I'm doing something really great here.

IMPORTANT! A note to commenters planning on advertising their business in comments: please be informed that I'm NOT going to post your comments but will ALWAYS mark them as SPAM.