I have the following code
// in functions.php
register_sidebar(array(
'before_widget' => '<section>',
'after_widget' => '</section>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
// in sidebar.php
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) : ?>
// static sidebar here ..
I find that the static sidebar is what renders even if I add widgets in the dashboard. I’m not sure if WP3.2 caused it as I never tried using dynamic sidebar before updating
1 Answer
You should add the name
and id
parameters to your register_sidebar()
argument array:
'name'=>'Sidebar Name',
'id'=>'sidebar-slug',
Like such:
register_sidebar(array(
'name'=>'Sidebar Name',
'id'=>'sidebar-slug',
'before_widget' => '<section>',
'after_widget' => '</section>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
Then call the id
of the Sidebar in your dynamic_sidebar()
call:
if ( ! dynamic_sidebar( 'sidebar-slug' ) ) {
}
By the way: you don’t need to include a function_exists( 'dynamic_sidebar' ) )
conditional; this functionality has been in WordPress since version 2.8.