Title: widget_text
Published: April 25, 2014
Last modified: February 24, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#wp--skip-link--target)

Filters the content of the Text widget.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#parameters)󠁿

 `$text`string

The widget content.

`$instance`array

Array of settings for the current widget.

`$widget`[WP_Widget_Text](https://developer.wordpress.org/reference/classes/wp_widget_text/)
|[WP_Widget_Custom_HTML](https://developer.wordpress.org/reference/classes/wp_widget_custom_html/)

Current text or HTML widget instance.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#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.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-text.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/widgets/class-wp-widget-text.php#L283)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/widgets/class-wp-widget-text.php#L283-L283)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Widget_Custom_HTML::widget()](https://developer.wordpress.org/reference/classes/wp_widget_custom_html/widget/)`wp-includes/widgets/class-wp-widget-custom-html.php` |

Outputs the content for the current Custom HTML widget instance.

  | 
| [WP_Widget_Text::widget()](https://developer.wordpress.org/reference/classes/wp_widget_text/widget/)`wp-includes/widgets/class-wp-widget-text.php` |

Outputs the content for the current Text widget instance.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.8.1](https://developer.wordpress.org/reference/since/4.8.1/) | The `$widget` param may now be a `WP_Widget_Custom_HTML` object in addition to a `WP_Widget_Text` object. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Added the `$widget` parameter. | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/widget_text/?output_format=md#comment-content-4671)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/widget_text/#comment-4671)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwidget_text%2F%23comment-4671)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwidget_text%2F%23comment-4671)
 4. Example migrated from Codex:
 5. The following performs a string replace on the content of the Text widget.
 6.     ```php
        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;
        }
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwidget_text%2F%3Freplytocom%3D4671%23feedback-editor-4671)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwidget_text%2F)
before being able to contribute a note or feedback.