0

I have registered two sidebars in my theme using the function below, but none of the widgets shows up in the sidebars even though I can manage them in the dashboard:

// register sidebars
add_action( 'widgets_init', 'my_register_sidebars' );
function my_register_sidebars() {

    register_sidebar(
        array(
            'id' => 'sidebar-left',
            'name' => __( 'sidebar-left' ),
            'description' => __( 'A short description of the sidebar.' ),
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="sidebar-title">',
            'after_title' => '</h2>'
        )
    );

        register_sidebar(
        array(
            'id' => 'sidebar-right',
            'name' => __( 'sidebar-right' ),
            'description' => __( 'A short description of the sidebar.' ),
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="sidebar-title">',
            'after_title' => '</h2>'
        )
    );
}

and to call template file is like this

<div id="sidebar-left" >

    <?php if ( is_active_sidebar( 'left' ) ) : ?>

        <?php dynamic_sidebar( 'left' ); ?>

    <?php else : ?>

        <p> here should be a left sidebar</p>

    <?php endif; ?>

</div>

The paragraph shows up but the widgets do not. Any suggestions?

  • Are you sure you're calling the sidebars in your theme? Right now you're just registering them. – Howdy_McGee Apr 25 '14 at 13:46
1

You've registered your sidebars with the ids of sidebar-left and sidebar-right but you are are attempting to display them using only left and right. You need to use the correct ids. That is:

dynamic_sidebar( 'sidebar-left' );

You need that id with both dynamic_sidebar() and is_active_sidebar()

if ( is_active_sidebar( 'sidebar-left' ) ) {
  dynamic_sidebar( 'sidebar-left' );
} else { ?>
  <p> here should be a left sidebar</p><?php 
}
  • I wanted to say thanks that solved it you saved me a lot of time. – yes_in Apr 25 '14 at 16:42
  • 1
    @Yassinz If this answer solved the problme please mark it as "Accepted". Look for the check mark at the top left under the vote arrows. – s_ha_dum Apr 25 '14 at 17:09

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.