5

Is there any filter which can be used in a plugin to process the content of the text widget before it is rendered?

7

Filter

  1. widget_text (for the text)
  2. widget_title (for the title)

Example

function add_smiley($content) {
$new_content = '';
$new_content.= $content . ':)';
return $new_content;
}   
add_filter('widget_text', 'add_smiley');

Note that this works only for the content so not if you have a widget with only a title.

Reference

  1. http://codex.wordpress.org/WordPress_Widgets
  2. https://stackoverflow.com/questions/1385954/do-wordpress-widget-or-sidebar-hooks-exist
  3. https://stackoverflow.com/search?q=wordpress+widget
  • Do you know any filter for custom widget? – Kyle KIM May 20 '17 at 0:50
4

You should be able to run a filter on widget_text. The text widget is the only one that calls the widget_text hook.

http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/default-widgets.php

Line 380 ..

$text = apply_filters( 'widget_text', $instance['text'], $instance );

So in short, Yes! Would be the direct answer to your question. Hope that helps... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.