WordPress Widget Codes

Line breaks and blank lines

Plain text typed or pasted in a text widget flows in one continuous paragraph. For line breaks you need this:

<br />

For blank lines you can use this (you can adjust it by changing the number):

<div style=”height:14px;”></div>

This code can also be used alone in a nameless text widget, as a spacer (to create more distance between other widgets).

Space around text

In some themes the text shows up too close to the widget borders; you create some space around it this way (you can change the number):

<div style=”padding:8px;”>

Text links

The plain code for a link to any webpage is this:

<a href=”URL HERE”>TEXT HERE</a>

In most cases it’s better to use this:

<a href=”URL HERE” target=”_blank”>TEXT HERE</a>

This way the link opens in a new browser window or tab, so that visitors don’t really leave your blog when clicking on a link.

E-mail link:



The content of several widgets (e.g. Categories, Links or Recent Posts) is unordered lists. The design of each theme presents unordered lists in its own way. If you want a list of items in a text widget to show up the same way, you use the code for unordered lists:

<li>ITEM ONE HERE</li>
<li>ITEM TWO HERE</li>

The code for nested lists (with indented sub-items) is like that:


<li>SUB1 HERE</li>
<li>SUB2 HERE</li>
<li>SUB3 HERE</li>

<li>SUB4 HERE</li>
<li>SUB5 HERE</li>
<li>SUB6 HERE</li>


This is an example with only two main items and three sub-items to each, but it’s enough for demonstrating the structure of the code.

Items and sub-items can be plain words or phrases, or any kind of allowed html code (e.g. links and/or style formatting).

Text widgets with unordered lists can also be used instead of some of the other widgets (such as the links widget or the categories widget). This can be useful if you don’t like the default appearance of those widgets and want to change it using formatting for style, or if you want your links or your categories in a non-alphabetical order; or if you want to include images. The drawback, of course, is that each time you add a new link or category you’ll have to update the text widget manually.


If you want to limit the length a text widget occupies in the sidebar, you can have its content in a (vertical) scroll box:

<div style=”height:150px;white-space:pre-wrap;overflow:auto;padding:8px;”>

The height number is just a suggestion – you can change it (but there’s a downward limit: below 45px there’s no room for the scrollbar). “Padding” is the space between borders and text – you can change that too. If you write an unordered list in a scrollbox, omit the padding altogether: the design of the theme will take care of that.

Or you may need a horizontal scrollbox:

<div style=”white-space:pre;overflow:auto;padding:8px;”>

In some themes it will look better if you create a visible border around the box; in that case add this right after the opening quotation mark:

border:solid 1px #999;


The code for a plain image is this:


For an image that links to a webpage:

<a href=”WEBPAGE URL HERE” target=”_blank”><img src=”IMAGE URL HERE” alt=”DESCRIPTIVE TEXT HERE” /></a>

Of course the image has to be narrow enough to fit in the sidebar (in most themes, sidebars are around 150 to 200 pixels wide). If you’ve got a wider image, you can downsize it to fit – example:

<img style=”width:150px;” src=”IMAGE URL HERE” alt=”DESCRIPTIVE TEXT HERE” />

But it’s better to use properly sized images: gives you faster loading, better quality, and no issues with Internet Explorer.

Also note that it’s better to use images uploaded to your own blog (via Media > Add New). If you use the URL of an image hosted in another site, you get the delay of that site loading as well (plus you run the risk of losing the image if it gets relocated or removed).

In some browsers you get a (blue) border around images. If you don’t want that, add this after “img” (with a space in between):


If you want a simple thin border around the image, you can add this after “img” (with a space before and a spacer after):

style=”border:1px solid #HEX NUMBER HERE;”

Image plus text

If you want a left-aligned image, with text wrapping around it, you need to add this after “img” (with a space before and a space after):

class=”alignleft” style=”margin-right: 8px;”

In some themes this may not work. For all kinds of combinations of image plus text, a more surefire way is coding for tables. (But that’s for a future post…)

If you’re having trouble placing text below an image, an easy alternative is using a second, untitled, text widget. (Note: when you add new widgets, you can rearrange them by dragging them into new positions.)

Looking for quality WordPress Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under WordPress | RSS 2.0

Author Spotlight

TJ Marsh

My name is Tj Marsh. I spend about 16 hours a day on the internet. Running my company and helping out here at Arvixe. I live in the good ole Arizona where it gets ridiculously hot. I love WordPress and a lot of other open source software along with coding.

Leave a Reply

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