I’m talking about the “Automatically add paragraphs” option that appears under the textarea in the “Text” widget. I swear I’ve done this before, but my Google-fu is failing me and all I can find is tutorials on existing WordPress widgets, nothing about how to code this into your own textarea/widget.
Anyone know how to add this/where in the codex this is? This is my widget now:
function form($instance) {
if($instance) {
$mytext = esc_textarea($instance['mytext']);
} else {
$mytext = '';
}
?>
<p>
<label for="<?php echo $this->get_field_id('mytext'); ?>"><?php _e('My Text', 'wp_widget_plugin'); ?></label>
<textarea rows="5" class="widefat" id="<?php echo $this->get_field_id('mytext'); ?>" name="<?php echo $this->get_field_name('mytext'); ?>"><?php echo $mytext; ?></textarea>
</p>
<?php
}
function widget($args, $instance) {
extract($args);
$mytext = $instance['mytext'];
echo $before_widget;
echo '<h1>' . $mytext . '</h1>';
echo $after_widget;
}
Check the sourcecode (line 524) of
default-widgets.php
in wp-include folder.The function you are looking for is wpautop
You can use wpautop to add paragraphs to your text