how do I detect whether a wordpress theme has sidebars

Mar 13, 2012   //   by   //   Blog, Wordpress Theme Tutorial  //  No Comments

I’m developing a wordpress plugin that needs to be able to detect whether the currently active theme has widget-capable sidebars, so that it knows whether it can add widgets or not. So, how do I detect whether the current theme is widget-aware?

there’s a couple of variables WP uses:

$wp_registered_sidebars and $wp_registered_widgets

Then, as per wp-admin/widgets.php:

$sidebars = array_keys($wp_registered_sidebars);

Don’t forget, WordPress does this itself – if there are no widget-read sidebars in a theme, the widgets.php page tells you so (if you look at wp-admin/widgets.php in the core, you’ll see how, but those 2 variables are the basis of it)

Leave a comment

Share This Post

RSS Wordpress News