Organize Your WordPress Sidebar Smartly
April 7th, 2010 by
WordPress widgets panel, is simple and easy to use with a sexy ajax interface.
However, the widget screen might not be enough to customize your sidebar like you really want to.
Even though you can add text widgets that contains HTML from the widget screen, I would not recommend it for three reasons:
- Unlike the post editor, the widgets screen doesn’t have a WYSIWYG interface, so it’s not so easy to control the layout, such as the way text wraps around an image, for example.
- You cannot enter javascript and php to widgets.
- Widgets are like plugins. The more you have, the more system resources are consumed and your blog becomes slow.
Now, before you say “you can turn the widget screen to be WYSIWYG with a plugin” or “you can add javascript and PHP to widgets after installing a plugin” – read my third reason again ![]()

Cutomizing your sidebar
For the case of example, let’s say you want to have a side bar that contains (top to bottom):
- A block of social media buttons.
- A banner presenting your new ebook.
- 4 Affiliate ad images.
- Tag cloud.
- Most popular posts.
- Recent Comments.
The tag cloud should have a rounded rectangle background like the following:

Add a fixed size image background will not be wise, because the rectangle height should expand every time tags are added.
The solution is very simple though:
This is the HTML:
//this div will have the upper background (the area at the top of the rounded box that contains 2 rounded corners)
<div id="topDiv"></div>
<div id="main">
//the tag cloud goes here and will have the main background (straight vertical lines in both sides of the content)
</div>
//this div will have the bottom background (the area at the bottom of the rounded box that contains 2 rounded corners)
<div id="botDiv"></div>
And this is the CSS:
<style type="text/css">
#topDiv{background:url(bgTop.gif) no-repeat}
#botDiv{background:url(bgBot.gif) no-repeat}
#main{url(bgMain.gif) repeat-y}
</style>
Where exactly should you type the above code?
Before I show you, let’s first see how WordPress grabs widgets for your dynamic sidebar.
If your WordPress theme supports dynamic sidebars, it should include 2 function calls:
- Inside your themes functions.php file –
register_sidebar(). - Inside your themes sidebar.php file –
dynamic_sidebar().
This function is what actually displays the widgets you have added.
Since the tag cloud is your 4th widget, you cannot type it above or below the dynamic_sidebar() function because if you do, the tag cloud will be the first or the last widget (correspondingly).
The solution is to register 2 sidebars.
Using multiple sidebars (and some code)
To add another sidebar, replace the register_sidebar() call in your functions.php file with
register_sidebar('sidebar1');
register_sidebar('sidebar2');
Then, your code in sidebar.php should be similar to the following:
<div id="sidebar">
//the first three widgets
<ul>
<?php dynamic_sidebar('Sidebar 1');?>
</ul>
//the tag cloud
<div id="topDiv"></div>
<div id="main">
<?php wp_tag_cloud( $args );?>
</div>
<div id="botDiv"></div>
//the remaining two widgets
<ul>
<?php dynamic_sidebar('Sidebar 2');?>
</ul>
</div>
Note: for more info about wp_tag_cloud() click here.
After customizing that tag cloud, let’s say you now decide to add a short bio and your image to the sidebar.
Only this time, it should be the first widget at the top so your sidebar.php should be similar to this:
<div id="sidebar">
//short bio and image
<div id="aboutMe">
<img src="myPic.jpg" alt="" />
I'm Omer Greenwald.
A web developer and a blogger.
<a title="about me" href="http://www.webtechwise.com/about-me/">(read some more about me)</a>.</div>
</div>
//the first three widgets
<ul>
<?php dynamic_sidebar('Sidebar 1');?>
</ul>
//the tag cloud
<div id="topDiv"></div>
<div id="main">
<?php wp_tag_cloud( $args );?>
</div>
<div id="botDiv"></div>
//the remaining two widgets
<ul>
<?php dynamic_sidebar('Sidebar 2');?>
</ul>
</div>
Finally, we get a useful combination of 2 dynamic sidebars, and some manual HTML and PHP. Was it worth it? definitely!
WordPress widgets screen should be used in 4 cases in my opinion:
- If you don’t want to deal with code at all whatsoever.
- If you can’t find a simple code replacement for the widget.
- If you tend to change your widgets very often (like once a week or once a month. and I’m sure you don’t).
In this case the comfort of a graphic interface is worth it. - When you develop a blog for someone who is not a developer and would like to be able to customize the widgets.
How do you control your sidebar widgets? Do you combine dynamic sidebar with manual PHP code?
Respond Here
10 responses
Trackbacks and Pingacks
- [User Link:Organize Your WordPress Sidebar Smartly] | Tips for Designers and Developers | tripwire magazine
- Organize Your WordPress Sidebar Smartly | WebTechWise | WordPressPlanet.com
- 150+ Irresistible Fresh Articles for Designers and Developers | tripwire magazine
- CSS Sprites – What, Why, How and When? | WebTechWise

Omer another great tut.
I have done some coding like this for my clients. I really should find the time to modify my theme and do some these tuts.
My theme has a lot of this stuff built in and I don’t really have to use widgets for it but I bet these basic coding tips still load faster than the built in stuff.
Thank James. Even though a theme can run smoothly with a lot of widgets intalled, it can always help to optimize it by replacing widgets with code.
Good post. I’ve been trying to ween myself off of plugins on all the blogs I manage. The more posts I read like this one, the easier it gets.
Thanks for your comment Zack.
That’s great know, did not know about that. Thanks for sharing
For an added performance boost, I’d recommend using WP Widget Cache. I run the majority of my site’s docking box sidebar through a single text widget which is indefinitely cached – this dramatically boosts performance.
Thanks for the tip Rishi, sounds like a good one.
This is just what I needed! Thanks for the great code.
well this well organization but its not applicable for all sites some sites require more banners some sites based on news so they use community sharing news and so on