Widgets & Sidebars

Posted on Wednesday, July 29th, 2009 at 11:40 am in

Every time I add widget (e.g. ‘Text’ or ‘Categories’) to the sidebar, the default sidebar content disappears.

This is common behaviour for widget-ready sidebars. The widgets replace the default sidebar content – even if you’ve only added a single widget. You can re-populate the sidebar in one of two ways.

The Simplest Option

Replace the missing sidebar listings with the appropriate widgets in using the Widgets option under Appearance within the Administration area. Drag and drop the widgets to obtain the sidebar content order you want and the sidebar will be automatically updated. If you change any widget settings (e.g. the title of a Text widget), remember to select “Save” to update that widget in your sidebar.

The Coding Option

If you want a mixture of widgets and default sidebar content, edit sidebar.php using the Editor option under Appearance in the Administration area. You need to look for the lines:

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

and

<?php endif; ?>

The code between these two lines will be automatically replaced by any widgets. So, it’s simply a matter of moving these lines until they only enclose the code that you want to be replaced.

Example Sidebar

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<li><h2>Pages</h2>
<ul>
<?php wp_list_pages('title_li&sort_column=menu_order'); ?>
</ul></li>

<li><h2>Recent Archives</h2>
<ul>
<?php wp_get_archives('type=monthly&limit=6'); ?>
</ul></li>

<?php endif; ?>

In the example above, any 1 or more widgets will replace both the listing for Pages and the Recent Archives list.

To retain the Recent Archives listing and add widgets to the sidebar, the code should be amended to:

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<li><h2>Pages</h2>
<ul>
<?php wp_list_pages('title_li&sort_column=menu_order'); ?>
</ul></li>

<?php endif; ?>

<li><h2>Recent Archives</h2>
<ul>
<?php wp_get_archives('type=monthly&limit=6'); ?>
</ul></li>

The Recent Archives will be now be displayed after any widgets in the sidebar.

Happy sidebar editing!

You might also be interested in

WordPress Support Services

Top