Search results

WordPress Tip: Add More Widget Areas to Your WordPress Theme

by Tom Johnson on Feb 7, 2010
categories: wordpress

You can add more than one sidebar section to your WordPress site. For example, with the stc-intermountain.org site, I added a whole bunch of additional sidebar sections in the Appearance > Widgets section.

Adding more sidebar sections

Adding more sidebars is useful if you're using WordPress more as a content management system than a blog.

Someone asked me how I did this. The process isn't hard. I've broken it down into three steps. (Before you continue with the instructions, you may want to back up the information in your existing sidebar.)

Step 1

Add this code to your functions.php file under Appearance > Editor.

<br />
if ( function_exists('register_sidebars') )<br />
        register_sidebar(array('name'=&gt;'Sidebar Home','before_title'=&gt;'<br />
','after_title'=&gt;'<br />
'));<br />
        register_sidebar(array('name'=&gt;'Sidebar Jobs','before_title'=&gt;'<br />
','after_title'=&gt;'<br />
'));<br />
        register_sidebar(array('name'=&gt;'Sidebar Meetings','before_title'=&gt;'<br />
','after_title'=&gt;'<br />
'));<br />

Note: Sometimes you have other sidebar code that looks similar to the above. If so, use it instead.

In this example, the sidebars that will be added will be called Sidebar Home, Sidebar Jobs, and Sidebar Meetings. Change the names to whatever you want. You can add many more sections here, not just three.

You can also add more arguments than simply name, before_title, and after-title. See the full function reference and arguments with registering sidebars.

You'll also need to delete the previous register_sidebars function so that the two don't conflict.

Step 2

Add a reference to the sidebar section where you want the sidebar to appear in your theme. For example, type the following to insert the Jobs sidebar:

<br />
&lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Jobs') ) : ?&gt;<br />

To insert the Meetings sidebar, you would type Sidebar Meetings rather than Sidebar Jobs.

Step 3

In a text editor, duplicate your existing sidebar code, rename the file (for example, sidebar_jobs.php), and FTP the file into the folder with your other theme files.

Where you want the file to appear (probably in a specific page template), add this reference to the file:

<br />
&lt;?php include (TEMPLATEPATH . '/sidebar_jobs.php'); ?&gt;<br />

Remove the other code that calls the sidebar (probably get_sidebar). Now that page template will show your Jobs sidebar. And you can configure your Jobs sidebar under Appearance > Widgets.

Although I've mainly been calling these sections a sidebar, you can create sections and insert them anywhere in your site, such as the footer, an ad space in the header, or elsewhere.

About Tom Johnson

Tom Johnson

I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, plain language, tech comm careers, and more. Check out my API documentation course if you're looking for more info about documenting APIs. Or see my posts on AI and AI course section for more on the latest in AI and tech comm.

If you're a technical writer and want to keep on top of the latest trends in the tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me. Finally, note that the opinions I express on my blog are my own points of view, not that of my employer.