1

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?

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' ); ?>
  • Oh, thanks! That was very stupid mistake of mine.. – Ziik Jun 27 '13 at 13:01
  • 1
    I've chased down typos like that for hours before. Now I tend to look for stuff like that first. – Pat J Jun 27 '13 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.