0

This question already has an answer here:

I have several sidebars (more then 1 on a page) and I would like to set different image sizes to widgets, depending in which sidebar they are located.

I tried

if( ! dynamic_sidebar('my-sidebar') ) :

and

if ( is_active_sidebar( 'left-sidebar' ) ) :

but this only seems to check if the sidebar's exist (and they do).

How do I get: "if widget is located in sidebar A, give me this size, elseif widget is located in sidebar B, give me that size"?

marked as duplicate by fuxia Mar 3 '14 at 15:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

EDIT:

Here I have registered 2 sidebars in functions.php with names sidebar1 and sidebar2.

$sidebar_args = array(
    'name'          => __( 'sidebar1', 'theme_text_domain' ),
    'id'            => 'sidebar-1',
    'description'   => '',
        'class'         => '',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget'  => '</li>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>' );

register_sidebar( $sidebar_args );


$sidebar_args_2 = array(
    'name'          => __( 'sidebar2', 'theme_text_domain' ),
    'id'            => 'sidebar-2',
    'description'   => '',
        'class'         => '',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget'  => '</li>',
    'before_title'  => '<h2 class="widgettitle">',
    'after_title'   => '</h2>' );

register_sidebar( $sidebar_args_2 );

And now retrieving their names on theme's page like this.

<?php
    global $wp_registered_sidebars;
    $my_sidebars = $wp_registered_sidebars;

    foreach($my_sidebars as $my_sidebar){
        echo $my_sidebar['name'];
    }

 ?>
  • Hey there, thank you so much! get_my_widgets(); is not doing anything in my theme (I did put the function in my functions.php like you said). Could you give me an example of the output it should give? – inTOWN Mar 3 '14 at 13:10
  • I have edited the code. Check now. – Sudeep K Rana Mar 3 '14 at 13:59

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