elegant themes

How to rename widgetized sidebars in WordPress

| November 20, 2008 | 2 Comments

You can manage multiple sidebar widgets in WordPress. To do so, you go to the Widgets page in the Admin, and select the Sidebar you want to manage. If you have 1 widgetized sidebar, the name “Sidebar 1″ is not a big deal for managing it. But what if you have 5 or more, and they’re named Sidebar 1, Sidebar 2, etc. Ah yes, now what was that wily sidebar 3 for?

Why would someone have so many sidebars to begin with? Well, remember that you can also add widget-ready sidebars to WordPress footers or anywhere in your design, to give extra content management options to clients.

Recently, we had a client with way too many widgetized sidebars to keep track of, so we had to find a new solution to change the standard widget sidebar names like “sidebar 1″ or “sidebar 2″ to something more meaningful like “Left sidebar” and “Right sidebar” in the admin area. I dug around the web and found 2 very helpful posts:

Here’s what I learned:

1. Go into your themes’s function.php file, or if it doesn’t exist, create it.

Add the following code:

<?php

if (function_exists(‘register_sidebar’))

{

register_sidebar(array(

‘before_widget’ => ‘<li>’,

‘after_widget’ => ‘</li>’,

‘before_title’ => ‘<h4>’,

‘after_title’ => ‘</h4>’,

‘name’ => ‘Left sidebar’

));

register_sidebar(array(

‘before_widget’ => ‘<li>’,

‘after_widget’ => ‘</li>’,

‘before_title’ => ‘<h4>’,

‘after_title’ => ‘</h4>’,

‘name’ => ‘Right sidebar’

));

}

?>

2a. Add a widgetized sidebar to your theme. Open up your theme’s sidebar file (for exampe, l_sidebar.php) and look for the first <ul> or <ul id=”sidebar”> or something similar, and add the following code:

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Left sidebar’) ) : ?>

2b. If your sidebar is already widgetized, find the following code

<?php if ( function_exists(‘dynamic_sidebar’) && dynamic_sidebar(1) ) : else : ?>

and replace it with

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Left sidebar’) ) : ?>

Then, find the closing </ul> at the very bottom of the file, and immediately before that, place

<?php endif; ?>

3. Now, if you go into your admin panel, under Design>Widgets, you’ll see the new names like in the image below.

Now you can easily manage your Widgets without trying to guess which one is which.

Tags: , , , ,

Category: Code Snippets, WordPress as CMS

About Rebecca Markowitz: Rebecca Markowitz has built over 50 WordPress sites for clients as Web Project Manager and WordPress specialist at illuminea. illuminea is a Jerusalem-based boutique web agency. WPGarage shows my dedicated relationship with WordPress over the years - full of love, laughs, tears, growth and strong drinks. L'chaim! View author profile.


Comments (2)

Trackback URL | Comments RSS Feed

  1. […] How to rename widgetized sidebars in WordPress (tags: WordPress tutorial widgets) Spread the word! […]

  2. Kimball says:

    Thanks! This was very helpful.
    -K

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.

More in Code Snippets, WordPress as CMS (25 of 54 articles)