Widgets not activated alert after using get_sidebar()

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:

Read More
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?

Related posts

1 comment

  1. You’ve changed from sidebar-main in your myfunc_sidebars_init() to sidebar1 in sidebar.php. Change sidebar.php to use

    <?php if ( is_active_sidebar( 'sidebar-main' ) ) : ?>
    
        <?php dynamic_sidebar( 'sidebar-main' ); ?>
    

Comments are closed.