• I have a theme with a custom widget area that I would like to default to containing a text widget pre-populated with some sample text (something like “here’s where you can put your intro text; go to the widgets panel to customize what this says”).

    I know I want to emulate what sidebar.php does (declare some default widgets that are turned on when you activate the theme; adding anything via the widgets panel overrides these defaults). I tried just pasting in the code from sidebar.php: works fine, but that code is for widgets such as the archive one, not the text widget, leaving me stumped on how to add the sample text.

    This page (http://codex.wordpress.org/Function_Reference/the_widget#Text_widget) says I should follow the format
    <?php the_widget('WP_Widget_Text', $instance, $args); ?>

    with default usage for the text widget looking like
    <?php the_widget('WP_Widget_Text'); ?>

    so currently my header.php (where the customized widget area in question resides) includes this code:

    <?php
    	if ( ! dynamic_sidebar( 'about-text-widget' ) ) : ?>
    			  <?php the_widget('WP_Widget_Text'); ?>
    <?php endif; ?>

    My PHP-n00b question is: how do I alter that code so that there isn’t only a default text widget appearing in my widget area, but a default text widget containing default text?

    This is a child theme of Twenty Ten, by the way, though I believe the question is not theme-specific. Much thanks for any advice!

  • The topic ‘Create default text widget that displays default text’ is closed to new replies.