apply_filters( ‘widget_text’, string $text, array $instance, WP_Widget_Text|WP_Widget_Custom_HTML $widget )

Filters the content of the Text widget.


The widget content.
Array of settings for the current widget.
Current text or HTML widget instance.

More Information

May also apply to some third party widgets as well. This filter hook can be used to replace any text within sidebar widgets.


$text = apply_filters( 'widget_text', $text, $instance, $this );


4.8.1The $widget param may now be a WP_Widget_Custom_HTML object in addition to a WP_Widget_Text object.
4.4.0Added the $widget parameter.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    The following performs a string replace on the content of the Text widget.

    add_filter('widget_text', 'wpdocs_text_replace');
    function wpdocs_text_replace($text, $instance, $that) {
        $search = 'welcome admin';
        $replace = 'welcome adam';
        $text = str_replace($search, $replace, $that);
        return $text;

You must log in before being able to contribute a note or feedback.