Thanks to @TomJNowell for his advise on using textarea
.
This is what I did to achieve what I wanted. It serves the purpose but I am not sure if it is the right way or not.
- I changed below input field:
<p>
<label for="<?php echo $this->get_field_id('headline'); ?>">Headline</label><br />
<input type="text" name="<?php echo $this->get_field_name('headline'); ?>" id="<?php echo $this->get_field_id('headline'); ?>" value="<?php echo $instance['headline']; ?>" class="widefat" />
</p>
To a textarea
:
<p>
<label for="<?php echo $this->get_field_id('headline'); ?>">Headline</label><br />
<textarea name="<?php echo $this->get_field_name('headline'); ?>" id="<?php echo $this->get_field_id('headline'); ?>" class="widefat" rows="5"><?php echo $instance['headline']; ?></textarea>
</p>
And this is my update function:
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
$instance = $old_instance;
$instance['headline'] = wp_kses_post($new_instance['headline']);
$instance['description'] = strip_tags( $new_instance['description'] );
$instance['link_title'] = strip_tags( $new_instance['link_title'] );
$instance['link_url'] = strip_tags( $new_instance['link_url'] );
$instance['image_uri'] = strip_tags( $new_instance['image_uri'] );
return $instance;
}