Easy as 1-2-3: Widgetize WordPress Themes
Easy as 1-2-3 is a new series here on Design Informer. The series will cover all kinds of tutorials, from Photoshop to WordPress. It will be really short and helpful tutorials that are easy to follow.
Part of what makes WordPress such a user-friendly platform is the endless supply of free widgets. With widgets, you can easily accessorize your blg without any knowledge of coding. (The majority of themes, however, keep this easy-to-use functionality exclusive to sidebars.) I recently widgetized my homepage in three easy steps, and I would like to share the process with you.
Step 1
The first thing you need to do is edit your functions.php file. I recommend you make a backup of the file on your local hard drive (just in case you break something.) Once you make a backup, it’s safe to add the following code to your functions.php:
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Homepage Widget 1',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
You have to give every widget a unique name. It’s a good idea to name a widget by where it is going to live. This widget houses the main image on my home page so I named it "Homepage Widget 1."
Also note that the ‘before_title’ and ‘after_title’ are set to h2 tags. Some themes are set to h3. Remember to make this adjustment if applicable.
Step 2
Open your home.php (or any file you wish to widgetize; the process is the same regardless) and add the following code:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage Widget 1') ) : ?>
<p>This area is widget ready.</p>
<?php endif; ?>
Note the first line of code gets the same widget name. (i.e ‘Homepage Widget 1′) The placement and stylistic attributes are all controlled by adding additional code to your theme’s style.css file.
Step 3
Go back to the widget area in your WordPress control panel and start rocking out. You are done!

What do you think of the new series, Easy as 1-2-3? Did you find this tutorial helpful?
We would love to hear your thoughts. Learning how to add widgets to WordPress themes is an important and valuable skill. Are there any other widgetizing techniques that you know? Please leave your comments below. We would really appreciate it. You can follow the Design Informer on Twitter here.




Konstantin
December 21st, 2009 2:39 amGreat tutorial Mario. I’m a plugin developer and I have some widgets out there public. I hate when people ask me to include a function or a shortcode for the widget because they haven’t got a widgetized sidebar. Thx for the post, perhaps I should send them over here ;)
Cheers,
~ K
P.S. Thx for putting up the subscribe to comments plugin ;)
.-= Konstantin´s latest Blog Entry – The Twitter API v2 Transition =-.
Jad Limcaco
December 21st, 2009 2:51 amThanks Konstantin. I’m glad you appreciated Mario’s tutorial. You should send them to this page. :)
Oh, and I finally was able to add the Subscribe to Comments plug-in. Thanks for the tip. As a matter of fact, I even took it a step further and added threaded comments to the blog as well. Took me a while but I really like the end result. :)
David Silva
December 21st, 2009 2:40 amnice. always a better to widgetize rather then hard code those side bar extras.
.-= David Silva´s latest Blog Entry – Premium Blog Service (2mo. FREE) =-.
Jad Limcaco
December 21st, 2009 2:52 amI agree. I actually didn’t know how to do this until this tutorial. Right now, some of the sidebar on Design Informer is hard-coded but I will definitely be following this tutorial in the next few days to widgetize all of Design informer.
webbografico
December 21st, 2009 2:43 amnice and simple tut… really helpful in my wp-theme-developer life
Jad Limcaco
December 21st, 2009 2:53 amI appreciate the compliments. I’m glad that you thought it was helpful.
Konstantin
December 21st, 2009 2:54 amJad, cool. Threaded comments look sweet, but I’m unable to continue the thread started above, there’s a limit of 2, oh well. Maybe you should try increase that number. Practice shows that 5 is generally enough, well at least on my blog ;)
.-= Konstantin´s latest Blog Entry – The Twitter API v2 Transition =-.
Jad Limcaco
December 21st, 2009 3:06 amYou’re right Konstantin. I just changed the limit to three. Thanks for pointing that out. :)
Konstantin
December 21st, 2009 3:08 amGreat! A tiny bit more space now, I like it. Keep up the good work guys! ;)
.-= Konstantin´s latest Blog Entry – The Twitter API v2 Transition =-.
Jad Limcaco
December 21st, 2009 3:09 amNo problem! It does look better when it is three deep.
A.Siraj Hassan Mohideen
December 21st, 2009 5:59 amThanks bro for this awesome tuto Merry Christmas :D ;)
Jad Limcaco
December 22nd, 2009 12:13 amMerry Christmas to you as well.
Mario Ocon
December 21st, 2009 7:02 amKonstantin
Thank you. I’m glad you found this helpful. I hope other will to.
David
I agree with you. In the long run it’s going to make updating your site alot easier.
Jad Limcaco
December 21st, 2009 11:43 amThank you for the excellent tutorial Mario. Looking forward to more excellent WordPress tips and tricks. :)
PixelTango
December 21st, 2009 8:38 amNice tutorial, keep up the good work! :)
Jad Limcaco
December 21st, 2009 11:54 amThanks! We’ll definitely do! :)
James Costa
December 21st, 2009 11:14 amGreat simple tutorial! Thanks!
Jad Limcaco
December 29th, 2009 12:45 pmYou’re welcome James. Keep up the great work with Phuse! :)
Tom
December 21st, 2009 12:02 pmSimple and short!
Thank you, that’s what i have been searching for…
.-= Tom´s latest Blog Entry – Mit dem Nikon AF-S Nikkor 300 mm 1:2,8G ED VR II legt Nikon die Messlatte höher =-.
Jad Limcaco
December 21st, 2009 12:59 pmI’m happy that you found what you were looking for. Thanks for letting us know.
Yousuf
December 22nd, 2009 12:06 amNice tut and simple too
Jad Limcaco
December 22nd, 2009 12:13 amThanks Yousuf. That’s what I’m trying to accomplish with the “Easy as 1-2-3″ series. Simple tutorials that anyone can try out in a few minutes. :)
Wcchyau
December 22nd, 2009 12:16 amThis Tutorial is short but really helpful! now I know how to manage my wordpress CMS more efficiently.
Jad Limcaco
December 22nd, 2009 12:36 amThanks! I myself didn’t know how to do this until I read this excellent tutorial by Mario. It will definitely allow me to code more sites in WordPress.
loswl
December 22nd, 2009 6:56 amVery cool tut, thanks for sharing, I love your threaded comments, would love to see a tut on that.
.-= loswl´s latest Blog Entry – David Choate Interview =-.
Jad Limcaco
December 22nd, 2009 10:42 amThanks Mark! I will definitely try to write a good tutorial on upgrading the WP pre 2.7 to have threaded comments. It took me so long to install threaded comments but I’m glad I was finally able to do it. It’s really working out great so far.
Karthick
December 22nd, 2009 7:48 amhi, this is a great tutorial, usually I will never use widgets. I will code them manually which is easy for me. However, this is very helpful for me, Thanks
.-= Karthick´s latest Blog Entry – Comuna2 Plazza Premium Joomla Template by TemplatePlazza =-.
Jad Limcaco
December 22nd, 2009 10:45 am:) Whatever works for you, but after learning this, I find it much easier than manual coding. It’s also perfect for client websites as well.
MCSE Angie
December 22nd, 2009 1:59 pmThe usability and sheer number of themes to fit any type of blog is probably the number one reason why I love WordPress more than any other blogger platform out there.
Jad Limcaco
December 23rd, 2009 11:53 pmYou’re right Angie. There’s plenty of great themes out there, some free and some not free. And there is also great support amongst other WP users so that’s why WP is awesome! :)
Amanda Eyer
December 23rd, 2009 7:07 amGreat resource. Simple and effective tips. Thanks for sharing.
Jad Limcaco
December 23rd, 2009 11:53 pmYou’re welcome Amanda. Look for more of these easy to implement tips in the next installment of Easy as 1-2-3.
iDale
January 13th, 2010 6:29 amGreat stuff!
I would love to find out how to add separate widgetized areas for different pages if anyone knows a simple way to do that?
So a sidebar for the homepage, a separate sidebar for the post page, archive page, etc
.-= iDale´s latest Blog Entry – Toxic Spill Coaster is Drop-Drink Gorgeous =-.
Jad Limcaco
January 13th, 2010 12:01 pmWell, all you would have to do for something like that is use custom templates and instead of calling a sidebar, you call that template that you created instead. If you’d like, I can send be more detailed.
Dinesh
January 14th, 2010 8:25 amThanks for the tutorial dude.
.-= Dinesh´s latest Blog Entry – Default https access for Gmail =-.
Jad Limcaco
January 14th, 2010 4:01 pmNo problem. Glad you liked it. ;)
Anja
February 9th, 2010 4:23 pmI don’t really understand how this is supposed to work. If you move the widget code to the home page and then add a widget in the WP widget area, wouldn’t the widget automatically be added to the sidebar, no the home page? Also, if you want some widget on the home page and some in the sidebar, how does each widget know where it belongs?
.-= Anja´s latest Blog Entry – WELCOME! =-.
Joe Howard
February 20th, 2010 1:58 amWidgets can be wherever you place them. Traditionally, the sidebar, but you can put widget “areas” anywhere. He suggest naming each widget a unique name so you can have one in your home.php called “Homepage Widget 1″ and another in your sidebar called “Sidebar Widget 1″. You’ll see two widget blocks in your dashboard, each named uniquely. So you can drag your text widget to your “homepage widget 1″ area and your recent comments widget to the “Sidebar Widget 1″ area.
.-= Joe Howard´s latest Blog Entry – Unlock the Hidden Job Market =-.
Jad Limcaco
February 24th, 2010 3:31 amThanks for the response on the question Joe! That was a really helpful answer and I appreciate you taking initiative to help out. :)
SmashinGeeks
February 18th, 2010 12:13 amNice Tutorial , thanks
.-= SmashinGeeks´s latest Blog Entry – How To Setup Co.Cc Domain With Your Blogspot Blog =-.
Jad Limcaco
February 24th, 2010 3:32 amYou’re very welcome! Hope it was helpful.
Doobbe
March 12th, 2010 6:31 pmGreat tut! Thx
Duane Kinsey
March 12th, 2010 9:14 pmExcellent tutorial. Great to hear that Easy as 1-2-3 is going to become a series.
Really looking forward to the upcoming tuts!
.-= Duane Kinsey´s latest Blog Entry – 13 Must Follow Logo and Brand Identity Design Blogs =-.
like_a_bauss
May 6th, 2010 6:23 pmFinally, been looking for this kind of coding.
Nice and easy to follow. Thx much. Bookmarked.
Sun Pietro
July 9th, 2010 4:41 pmThanks a lot for that post.
It’s easy to follow and I have widgets in my template.
Jad Limcaco
December 21st, 2009 11:54 amI’d like to see it implemented on your site. Send me a link when you finish.