Search code examples
wordpressthemeswordpress-themingsidebar

how do I detect whether a wordpress theme has sidebars


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?


Solution

  • You'll be glad to hear there's a couple of variables which 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)