I am trying to get rid of the following error in debug:
Notice: register_sidebar was called <strong>incorrectly</strong>.
No <code>id</code> was set in the arguments array for the "Header" sidebar.
So when I register that sidebar I added the id parameter like so:
register_sidebar(array(
'id' => 'header-sidebar',
'name' => 'Header',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
Now no matter if I use the name field or the id field dynamic_sidebar
always returns false.
I've tried:
dynamic_sidebar( 'Header' );
and
dynamic_sidebar( 'header-sidebar' );
My understand is both of the above should work. Note if I comment out the id parameter in the register_sidebar call and use dynamic_sidebar( 'Header' );
everything works fine. What am I missing?
This is WP 4.2.2.
So per these directions: List all sidebar names? I was able to list all the sidebar names and when I set the id parameter with register_sidebar
the id in the list of names changes. The specific sidebar I'm playing with now is 'sidebar-5' before setting an id and 'sidebar-jsp' after. Once the id field is set I can not use dynamic_sidebar
with the name 'Sidebar', the original id 'sidebar-5' or the new id 'sidebar-jsp'.
Per s_ha_dum's suggestion I wrapped a single sidebar inside a function so that I could make it happen after 'widgets_init'. This did not work.
function register_header_sidebar_jsp() {
register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar-jsp',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
}
add_action( 'widgets_init', 'register_header_sidebar_jsp' );
I'm calling it right now with:
<?php var_dump(dynamic_sidebar('sidebar-jsp')); ?>
I'm not sure what's going on but I don't have all day to mess with this. Thanks for your suggestions everyone.