Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In custom theme development, how does one enable default built-in widgets? Note I mean default built-in widgets, not custom ones. I tried the following example for a WP 3.12 blog by placing it in my theme's functions.php file, trying to activate Pages by default. It didn't work, but I don't know why.

function mytheme_widget_init(){
  $asOps = array(
    'classname' => 'widget_pages',
    'description' => __( "")
  );
  wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $asOps);
}

add_action('widgets_init','mytheme_widget_init');

What am I doing wrong?

EDIT: THE SOLUTION

In my theme, I needed to re-edit sidebar.php and use this markup instead.

<?php ?>
<div id="sidebar" role="complementary">
    <ul>

<?php if ( !dynamic_sidebar(1) ) : ?>
<?php endif; ?>

<?php if ( !is_active_sidebar(1) ) : ?>

    <li id="search" class="widget-container widget_search">
        <?php get_search_form(); ?>
    </li>

    <li id="categories" class="widet-container widget_categories">
        <?php wp_list_categories('show_option_none=&title_li=<h2>' . __('Categories') . '</h2>' ); ?>
    </li>

    <li id="archives" class="widget-container widget_archives">
        <h2 class="widget-title">Archives</h2>
        <ul>
            <?php wp_get_archives( 'type=monthly' ); ?>
        </ul>
    </li>

    <li id="pages" class="widget-container widget_pages">
        <ul>
            <?php wp_list_pages('title_li=<h2>' . __('Pages') . '</h2>'); ?>
        </ul>
    </li>

<?php endif; ?>

    </ul>
</div><!-- sidebar -->
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

that's not the way, wp_register_sidebar_widget is used to create widgets. if you want your sidebar to display widgets by default use [dynamic_sidebar()][1] in your theme eg from the 2010 theme:

<div id="primary" class="widget-area" role="complementary">
            <ul class="xoxo">

<?php
    /* When we call the dynamic_sidebar() function, it'll spit out
     * the widgets for that widget area. If it instead returns false,
     * then the sidebar simply doesn't exist, so we'll hard-code in
     * some default sidebar stuff just in case.
     */
    if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>

            <li id="search" class="widget-container widget_search">
                <?php get_search_form(); ?>
            </li>

            <li id="archives" class="widget-container">
                <h3 class="widget-title"><?php _e( 'Archives', 'twentyten' ); ?></h3>
                <ul>
                    <?php wp_get_archives( 'type=monthly' ); ?>
                </ul>
            </li>

            <li id="meta" class="widget-container">
                <h3 class="widget-title"><?php _e( 'Meta', 'twentyten' ); ?></h3>
                <ul>
                    <?php wp_register(); ?>
                    <li><?php wp_loginout(); ?></li>
                    <?php wp_meta(); ?>
                </ul>
            </li>

        <?php endif; // end primary widget area ?>
            </ul>
        </div><!-- #primary .widget-area -->
share|improve this answer
    
You were absolutely right. I'm going to amend my question with the solution I ultimately went with, but I want to give you credit for the solution. –  Volomike May 6 '11 at 20:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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