How to Add Widget Areas to Your WordPress Theme

August 4, 2009
Share via email

Just found this fantastic tutorial on adding widget areas to any WordPress theme. I successfully set up a new widget area below the content of my posts on another blog I write for in about 5 minutes.

Addwidget Area to Theme: Step 1.

In the index.php file in your theme directory, add the following code to an area where you would like a new widget area. Directly below the content is a good idea if you wish to place adverts, or further reading there. Note we have had to wrap this line of code so it displays. Careful of too many spaces.

<div>
	<?php if ( !function_exists('dynamic_sidebar') || 
!dynamic_sidebar('Post Widget') ) : ?>
	<?php endif; ?>
</div>

Step 2.

Then in the functions.php file add the following line, directly below the current widget code:

register_sidebar(array('name'=>'Post Widget',));

Step 3.

Finally, to style the wdiget, add this code to the style.css file:

.widget_post {
	background: #FFFFFF;
	margin: 0px;
	padding: 10px;
	width: 600px;
	}

It really is as simple as that. When you next go to the widgets area in your WordPress control panel, you will see an option for “Post Widget”. There is a more detailed explanation on StudioGrasshopper’s website.

Source: Studiograsshopper.ch -How to add a Widgetised area in a WordPress theme

Tags:

8 Responses to How to Add Widget Areas to Your WordPress Theme

  1. Web Design Norwich on October 15, 2010 at 12:04 pm

    I didn’t realise it was so simple, thanks for this.

  2. Webologist on October 15, 2010 at 12:24 pm

    Don’t let your clients hear you say that!

  3. Dustin Ring on October 23, 2010 at 8:28 pm

    Thank you very much! Worded flawlessly.

  4. Victoria on November 19, 2010 at 3:58 pm

    Finally a simple solution that works! So many other people seem to make this more difficult than it is. Your solution workded perfectly first time. Much appreciated! Thank you.

  5. Webologist on November 19, 2010 at 4:20 pm

    Glad it still works OK! This was written quite a few versions back and when I tried it on one theme I got in a bit of a mess!

  6. Tavares on December 8, 2010 at 1:35 pm

    good job! tks!!

  7. Ritergal on March 4, 2011 at 2:51 am

    I’m new to this and feel like I’m climbing a cliff without a map.

    The index.php file in the Atahualpa theme folder is short*. I have no clue where to put that code.

    Is this the right file? Any input welcome.

    ****************

  8. Webologist on March 4, 2011 at 2:53 am

    Some themes do things differently. I thought that Atahualpa was pretty flexible though as far as widgets are concerned. Sometimes you need to modify functions.php.

Leave a Reply

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

*