Take the 2-minute tour ×

Is there a function to retrieve the WordPress sidebar(s) that is displayed in the current front end?

share|improve this question
add comment

1 Answer

I posted a solution that might work, here: Checking If A WordPress Widget Displayed In The Current Front End

dynamic_sidebar doesn't register that it's been called for that and that sidebar. Neither is there a suitable hook to do this yourself. So I'm afraid you would have to tell Wordpress for each template what sidebars are being displayed. One way to do this would be to create a wrapper function like this

function wrap_dynamic_sidebar( $sidebar_id )
    global $sidebars_in_this_template;
    $sidebars_in_this_template[] = $sidebar_id;
    return dynamic_sidebar( $sidebar_id );

And replace dynamic_sidebar with this everywhere (but I understand that it is very likely this solution will not be feasible for you).

If you want to display a list of all sidebars, you could use $wp_registered_sidebars

global $wp_registered_sidebars;
$sidebar_ids = array_keys( $wp_registered_sidebars );
share|improve this answer
Assuming we are creating plugins and replacing dynamic_sidebar in all templates is hard to do. –  zourbuth Nov 16 '12 at 4:39
There are many scenarios like it; child themes and so on. But the lack of filter in dynamic_sidebar that passes on the sidebar ID means there really isn't any perfect solution. It's not that we haven't found it. It just doesn't exist. –  Pickett Nov 16 '12 at 6:11
add comment

Your Answer


