In the previous recipe, I showed you how to install a widget. Unfortunately, many themes still can't handle widgets by default. In this recipe, I'll show you how to make your sidebar ready for widgets.
First, be sure that your theme sidebar isn't widget-ready. To do so, refer to the previous recipe. If you are sure that it is not widget-ready, proceed with the following steps.
Open the
sidebar.php
file from your theme and add the following code:<ul> <?php /* Widgetized sidebar, if you have the plugin installed. */ if ( !function_exists('dynamic_sidebar') ||!dynamic_sidebar() ) : ?> <?php endif; ?> </ul>
Save the file and open
functions.php
. If this file doesn't exist, create one. Then, paste the following code in it:if ( function_exists('register_sidebar')) register_sidebar(array( 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => ...