• This is code from my themes functions.php file. I want to add categories widget in here by default, so that the user won’t have to manually drag and drop categories widget to the sidebar inside admin widget page. How to do that? Thanks ??

    function twentyeleven_widgets_init() {
    	register_widget( 'Twenty_Eleven_Ephemera_Widget' );
    	register_sidebar(array(
    		'name' => 'Category Top',
    		'id' => 'sidebar-category-top',
    		'description' => __( 'Put here the widget category', 'twentyeleven' ),
    		'before_widget' => '<div class="category-top">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    
    }
    add_action( 'widgets_init', 'twentyeleven_widgets_init' );

    The end result should be: When user activates theme, he sees this when clicking widgets page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Do not edit the Twenty Eleven theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. Create a child theme for your changes.

    Thread Starter ak47marx

    (@ak47marx)

    Thanks esmi, but this is already a child theme, it is built on Twenty Eleven theme.

    Any ideas how to hard code categories widget into sidebar? ??

    You need to be editing sidebar.php. You can add the relevant WP template tags to produce a default menu or you can use something like:

    <?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
    <aside id="search" class="widget widget_search">
    <?php the_widget('WP_Widget_Search'); ?></aside>
    
    <aside id="archives" class="widget"><?php the_widget('WP_Widget_Archives'); ?>
    </aside>
    [.. etc ..]
    <?php endif;?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Categories widget in theme by default, after activating.’ is closed to new replies.