I stumbled upon avery strange problem while creating a sidebar for my wordpress theme using the get_sidebar() function in header.php.
I inserted the following code in function.php:
function myfunc_sidebars_init() {
register_sidebar(array(
'name' => __('Main Sidebar', 'mytheme'),
'description' => __('Widget area for the main sidebar.', 'mytheme'),
'id' => 'sidebar-main',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
}
}
add_action( 'widgets_init', 'myfunc_sidebars_init' );
My sideber.php looks like this:
<div id="sidebar1" class="fluid-sidebar sidebar span4" role="complementary">
<?php if ( is_active_sidebar( 'sidebar1' ) ) : ?>
<?php dynamic_sidebar( 'sidebar1' ); ?>
<?php else : ?>
<div class="alert alert-message">
<p><?php _e("Please activate some Widgets","mytheme"); ?>.</p>
</div>
<?php endif; ?>
</div>
I also selected the sidebar in Appearance->Menus in the admin panel and all default widgets are added to the sidebar in Appearance->Widgets (Search, Recent Posts, Recent Comments, etc.).
However after loading the theme there is an alert in the sidebar menu saying “Please activate some Widgets”. Why is that and how can I fix it?
You’ve changed from
sidebar-main
in yourmyfunc_sidebars_init()
tosidebar1
insidebar.php
. Changesidebar.php
to use