In WP theme building, if a sidebar is not active, can I turn it on? Also, if the sidebar is active, and doesn't contain any widgets, can I add some?

I'm a theme and plugin developer, but this is something I haven't learned to do yet.



When you register a sidebar in your themes functions it will be active in the dashboard. If no widgets are added to your sidebars WordPress will add the default widgets. You can prevent WordPress from adding the default widgets by unregistering them:

// Remove WP default Widgets
    // WP 2.8 function using $widget_class
    if (function_exists('unregister_widget')) {

    // pre WP 2.8 function using $id
    } else {

You can also preset your own widgets.

// The following code sample is from The Thematic Theme which is licensed under the GPLv2

    register_sidebar_widget(__('Search', 'thematic'), 'widget_thematic_search', null, 'search');
    register_sidebar_widget(__('Meta', 'thematic'), 'widget_thematic_meta', null, 'meta');
    register_sidebar_widget(array(__('RSS Links', 'thematic'), 'widgets'), 'widget_thematic_rsslinks');
    register_widget_control(array(__('RSS Links', 'thematic'), 'widgets'), 'widget_thematic_rsslinks_control', 300, 90);

    // Pre-set Widgets
    $preset_widgets = array (
        'primary-aside'  => array( 'search', 'pages', 'categories', 'archives' ),
        'secondary-aside'  => array( 'links', 'rss-links', 'meta' )

    if ( isset( $_GET['activated'] ) ) {
        update_option( 'sidebars_widgets', apply_filters('thematic_preset_widgets',$preset_widgets ));

Thematic is actually a great example of all the things that can be done with widgets. Take a look at widgets.php and widgets-extensions.php

  • 1
    Thematic can be a little blunt and completely ignore a lot of built in WordPress functionality. This may be for backward compatibility but you have to cut the chord some time. Instead of checking $_GET['activated'] use the built in API and use the switch_theme action to test the installed widgets and make your necessary changes. – Gipetto Sep 18 '10 at 6:54
  • The final solution is here: wordpress.stackexchange.com/questions/16603/… – Volomike May 7 '11 at 4:25

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.