WordPress: Adding a Widget Area to a Theme
Finding the right WordPress theme for your project can sometimes be difficult. Finding a theme with the features you like is even harder. Luckily adding widget areas to your theme is a straight forward task.
First you must register the widget sidebar in your functions.php file within the theme, be sure to place the following code inside your PHP tags <?php and ?>.
1 2 3 4 5 6 7 8 9 10 11 12 |
/*Add a Widgetized Sidebar*/ if ( function_exists('register_sidebar') ){ register_sidebar(array( 'name' => 'Homepage Sidebar', 'id' => 'homepage_sidebar', 'description' => 'This is the home page sidebar', 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>', )); } |
After registering the sidebar simply add the following code where you want the widget to appear.
1 2 |
<!-- Widgetized Sidebar --> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('homepage_sidebar') ) : ?><?php endif; ?> |
Find out more about this in the WordPress Codex here.
Recent Comments