5 Useful And Creative Ways To Use WordPress Widgets
If you’ve been reading some of the previous WordPress-related articles here on Smashing Magazine, you’ll know that WordPress is much more than a blogging platform. It can be used as a CMS, too. And WordPress widgets are a powerful tool in your WordPress development arsenal.
When you think of WordPress widgets, you may think they’re just a way to rearrange various items in your blog’s sidebar without touching any code. Sure, that’s nice and all, but that’s really just the tip of the iceberg of all the things WordPress widgets can do.
You may be interested in the following related posts:
- Power Tips For WordPress Template Developers
- 10 Useful WordPress Loop Hacks
- Custom Field Hacks For WordPress
- 15 Useful Twitter Hacks and Plugins For WordPress
- Mastering WordPress Shortcuts
- 100 Amazing Free WordPress Themes For 2009
1. Multiple Widget-Ready Areas
.jpg)
A widgetized theme has come to be expected by theme users and developers alike. Nowadays, however, just one widgetized area doesn’t cut it. The first step to using widgets on your WordPress website is to widgetize your theme, and that’s really not that hard if you have the right code in place.
Register the Widget Areas
To have multiple widget-ready areas, the first thing to do is register the widget areas in the functions.php file of your WordPress theme. Let’s say you have a three-column theme, and you want to have two different sidebars on the left and right side:
<?php
register_sidebar( array(
'name' => 'left-sidebar',
'id' => 'left-sidebar',
'before_widget' => '<div id="%1$s" class="%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
register_sidebar( array(
'name' => 'right-sidebar',
'id' => 'right-sidebar',
'before_widget' => '<div id="%1$s" class="%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
?>
Activate the Widget Areas
The next step is to put the dynamic sidebar code in the actual sidebar files. Depending on your theme, this could be located in a sidebar.php file, or elsewhere. Here’s the code to use:
<?php if (!dynamic_sidebar("left-sidebar") ) : ?>
Default left sidebar stuff here…
<?php endif; ?>
<?php if (!dynamic_sidebar("right-sidebar") ) : ?>
Default right sidebar stuff here…
<?php endif; ?>
The code between the PHP tags will be displayed if no widgets are currently used in the relevant widget area. For example, if no widgets are used in the “left-sidebar” widget, then “Default left sidebar stuff here…” would be displayed instead.
Sources:
2. Widget Logic

Sometimes you may not want the same widgets to appear the same way on every single page of your blog. This is where the Widget Logic plug-in comes in handy.
After the plug-in is installed, a new “Widget Logic” input box is displayed in the options box of every widget you use. In this box, you can type a series of WordPress conditional tags to control where exactly the widget is displayed.
In the screenshot above, the Calendar widget is set to display only on the page called “Evil.” You can use many more conditional tags as well.
Examples
- Display only on the home page:
is_home() - Display only on individual posts:
is_single() - Display only on pages:
is_page() - Display on archive pages (category, tag, etc.):
is_archive() - Display on search results pages:
is_search() - Display on all pages except the home page:
!is_home() - Display on “Advertise” or “Contact” page:
is_page('advertise') || is_page('contact')
Simply type something similar in your own Widget Logic boxes, depending on where you want the widgets to display.
Sources:
- The Ultimate Guide to WordPress Conditional Tags
- WordPress Conditional Tags (WordPress Codex)
3. Query Posts

For those who don’t know, the query_posts template tag is a powerful WordPress function that you can use to control how different posts and pages show up in the loop.
However, if you’d rather not mess around with more PHP code than is necessary but still want to take advantage of the query_posts tag, you can use the Query Posts widget to display WordPress content in almost any way you can think of.
After installing and activating the plug-in, you will have a new “Query Posts” widget available in the WordPress widgets menu.
What It Can Do
- Display posts by tag, category, author, time/date or custom field keys/values,
- Display however many number of posts you want,
- Order posts by date published, title or ID in either ascending or descending order,
- Display posts with full content, as excerpts or in a list,
- Show WordPress pages.
Source:
4. 404 Templates
.jpg)
A lot of WordPress themes out there, including the default WordPress theme, don’t offer anything useful in their 404 templates. For example, if you land on a 404 page of a WordPress website that uses the default theme, you’ll be greeted with a message that says “Error 404 – Not Found,” and that’s it.
There are plenty of WordPress widgets you can use to spice up your 404 page and make it more useful to visitors who are trying to find content. The widgets “Recent Posts,” “Categories” and “Archives” come to mind.
The Code
The first step is to register the widget area in WordPress. To do this, open up your theme’s functions.php file, and put the following code in it:
<?php
register_sidebar( array(
'name' => '404',
'id' => '404',
'before_widget' => '<div id="%1$s" class="%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
?>
Now that the widget is registered, you’ll have to edit your theme’s 404.php file and add the following code:
<?php dynamic_sidebar( '404' ); ?>
That’s it. You can now place any widgets you’d like in your “404″ widget, and they will be displayed every time a visitor lands on a 404 page. Load it up with things like a search box, recent posts, category listings or maybe a few Query Post lists.
Source:
5. Insert Ads Between Posts
.jpg)
You can code your theme to insert a widget in between a certain number of posts. Some people use this to insert advertising, but the sky is the limit when it comes to widgets.
The Code
As we did when widgetizing the 404 template, the first step to setting this up is to register the widget area for the index insert. Open up your functions.php file again and insert this similar code:
<?php
register_sidebar( array(
'name' => 'index-insert',
'id' => 'index-insert',
'before_widget' => '<div id="%1$s" class="%2$s widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
?>
To set it up on your main index page, you’ll need to open up the index.php file of your theme, locate the “endwhile” near the end and put the following code directly above it, so that it looks like this.
<?php if ($count==2) { ?>
<?php dynamic_sidebar('index-insert') ?>
<?php } ?>
<?php $count = $count + 1; ?>
<?php endwhile; ?>
The above code will insert the “index-insert” widget area right after the second post. You can change the $count==2 number to something else, according to the post you’d like the widget area to be displayed after.
If you want ads to show up in between your archive listings, such as on category or tag pages, you may have to insert the above code in other files, including archive.php, category.php and tag.php. You can even control which ads are displayed on which pages by using conditional tags, such as is_archive(), is_category() and is_tag(), in the Widget Logic plug-in.
Source:
More Widget Resources
- Add a Widgetized Footer to Your WordPress Theme
A tutorial that teaches you how to code your own widgetized footer, including the HTML, CSS and WordPress code needed. - List of WordPress Widgets
A list of WordPress widgets from the Codex, as well as several other widget-related resources.
Related posts
You may be interested in the following related posts:
- Power Tips For WordPress Template Developers
- 10 Useful WordPress Loop Hacks
- Custom Field Hacks For WordPress
- 15 Useful Twitter Hacks and Plugins For WordPress
- Mastering WordPress Shortcuts
- 100 Amazing Free WordPress Themes For 2009
(al)


Vu Nam Hung
July 14th, 2009 3:32 pmThanks, I love Widget Logic
BraintreeGeek
July 14th, 2009 3:37 pmAnother great article by SM. Thanks once again!
zaryl
July 14th, 2009 3:56 pmhoho. straightforward and easy to understand. well done!
Simon Food Favourites
July 14th, 2009 5:06 pmany widgets for Blogger?
ardyonline
July 14th, 2009 5:20 pmway cool! i must try this one!
im wordpress fan! :)
thanks for sharing this!
Keith
July 14th, 2009 5:48 pmAnother great article, Leland ;)
AMinoOo
July 14th, 2009 8:19 pmYEEEEEEEEEh it’s great.
Sankar
July 14th, 2009 9:59 pmNice article on Word press widgets. WordPress users should say thanks to authors of smashing magazine for all the tips.
Thanks
Sankar
stoimen
July 14th, 2009 10:02 pmGreat overview! Nice job, keep going!
Simon Harlinghausen
July 14th, 2009 10:18 pmInteresting post. Quite useful.
Thanks
Frog
July 14th, 2009 10:50 pmFinally a WordPress post my tiny mind can decipher, good work!
iLiThYa
July 14th, 2009 10:54 pmThanks for the tips! Very useful.
Patrick
July 14th, 2009 11:15 pmWow! What a great Post thank u for this! :)
Gerri Elder
July 14th, 2009 11:16 pmThis is so helpful. Thank you for presenting and explaining these so well.
bolix
July 14th, 2009 11:56 pmJust what I need! Thank you very much :)
That Widget Logic looks great.
Ravindra
July 15th, 2009 1:33 amVery nice post. Thnks You.
Luc
July 15th, 2009 1:53 amWp logic should be a shame for any CMS.
How can you even consider acceptable the fact of allowing a user to input “php code” in a configuration stuff.
user do not have to deal with the code. the code is the geek’s stuff, not the user’s stuff…
Aaron Smith
July 15th, 2009 2:10 amAnother wonderful post about WordPress. Love WordPress, Love Smashing..
Lloyd
July 15th, 2009 2:50 amJust what i was looking for… thanx
Leland Fiegel
July 15th, 2009 3:17 amThanks everyone, glad you all like the article!
@Luc: I partially agree with you, but not sure I would call it a “shame” though.
Hopefully the conditional tags are pretty easy to understand, even for an average user. You can simply copy and paste them from the WordPress codex and edit them for your own purposes.
It may not be the friendliest interface for an average user, but the way the Widget Logic plugin is set up now makes it very flexible to control exactly where you want your widgets to display
Adam W. Warner
July 15th, 2009 4:15 amGreat article Leland, and thanks for linking to my Query Posts video tutorial. I plan to create many more videos for many other plugins:)
Corey Freeman
July 15th, 2009 8:49 amThanks for the awesome article!
James Holmes
July 15th, 2009 11:32 amLeland -
This is an excellent post. It is a bit advanced for most users, but it illustrates that if a person is willing to put some time in to learning several straight forward steps you can take your Word Press blog a higher level in function and impact.
Thank you!
mbreti3gut
July 15th, 2009 11:35 amThanks for this awesome article. It’s just what i was looking for.
Leland Fiegel
July 15th, 2009 12:25 pmAppreciate all the comments!
@Adam W. Warner: No problem. It’s a great video and very relevant to this article. Looking forward to the other videos you have in store for other plugins.
Luis Eduardo
July 15th, 2009 1:27 pmthis article is awesome, i’ll try some of those widgets, right now
Clarence Johnson
July 15th, 2009 1:40 pmThank you. Thank you. I have been searching for a concise tutorial on how to widegtize my WP theme and you guys met my expectations.
Clarence
Jay (blaszta.com)
July 15th, 2009 6:36 pmGreat & straight forward article! Like it a lot!
enej
July 16th, 2009 12:29 amIf you really like the Widget Logic
you should check out the section widget. It’s a wicked brand new plugin.
anubis
July 16th, 2009 9:57 amI’m new to this and am wondering…. when you say “Open up your functions.php file again and insert this similar code:” where exactly on that page do you drop that code? In the beginning? Thanks!
Leland Fiegel
July 16th, 2009 10:32 am@anubis: It doesn’t really matter. Just make sure the functions.php file begins with a <?php and ends with a ?> with no spaces or line breaks before and after, otherwise it could cause errors.
Godfrey Chan
July 16th, 2009 1:20 pm@Luc @Leland Fiegel Check out our Section Widget ().
Jessi
July 16th, 2009 7:34 pmGreat post.
There’s an alternative to Widget Logic that I’ve been using: Widget Block. And instead of typing in conditional tags, you only have to put in the URL/s: Screenshot
Leland Fiegel
July 17th, 2009 6:01 am@Godfrey Chan: Thanks for the link. That plugin looks very interesting. It’s kind of like a text widget, with conditional functionality built in?
@Jessi: Nice find. Can you use it for anything besides pages/subpages though?
Sankar
July 17th, 2009 11:14 pmIt’s sounds quite good.
-San
Netcell
July 18th, 2009 2:53 amSo useful, Thank you very much for sharing this article
carol hagen
November 2nd, 2009 2:48 pmI subscribed to your RSS feed, but I was disappointed that you did not offer the option to have it appear on my igoogle homepage. You should use feedburner to get this option activated and optimize your feeds.
Glenn Bennett
December 1st, 2009 9:16 amThose who are messing around with widgets might want to check out my little widget making tool at widgetifyr.com. I created it for my own use, but others seem to be find it useful. Let me know what you think.
Bono
October 29th, 2011 7:30 pmGrade A stuff. I’m unqesutinoalby in your debt.
Adriaan Fenwick
December 22nd, 2009 12:08 amI was having a lot of problems registering multiple widgets, because when I went to the admin area my widgets would sometimes dissapear or be ordered differently.
After implementing my widgets in the way described above it seems to be working fine now.
Thanks SM!!
CSS Menu Samples
February 22nd, 2010 8:56 pmawesome article… thanks a lot.
howard
April 27th, 2010 10:30 pmthank you! it works!
Pratish
May 2nd, 2010 11:14 amWidget logic saved me a ton of time – was creating different sidebars for different pages before that.. thanks!
Elman
May 12th, 2010 2:46 amGuys, I am struggling to find the widgets to edit them. I have “recent comments”, “recent posts”, “calendar” widgets added to my blog but I can’t find them to edit. My blog is another language, so I would like to change some of the words displayed on the blog. I have done this pretty much with rest of the blog, because I know where root files are located. But I cannot find WP default widgets’ files to change. Any help is really appreciated.
http://www.deffektiv.com
Thanks,
Elman.
Jonathan Puddle
June 23rd, 2010 2:12 amThanks, some of these are awesome!
Naveed Saeed
September 5th, 2010 1:30 amI have successfully added and created the 404 Widget last night ..
everything working fine but the problem now is that i have closed the browser and after a refresh the Sidebar widgets are having the options (categories, rss, Tag Cloud etc…)
but
the 404 is empty while during error it shows all the widgets i have added yesterday to it.
Please HELP
Mariam Duell
September 12th, 2010 2:24 amGood news brother
fanta
March 29th, 2011 11:02 amCan someone explain please how to name the sidebar files and then include them properly in the template??? I can’t make it work because each tutorial lacks this information! I know what to put in function.php to ahve multiple sidebars, but where to put the dynamic codes, how WP will know where to look for proper sidebar?
Michelle Cohen
February 19th, 2012 8:14 pmI’ve really been wondering how (or if it was possible) to stick a widget between posts on my home/main index page! Limiting them to sidebars & footer seems so, well, limiting. thanks!