Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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. http://stackoverflow.com/questions/1385954/do-wordpress-widget-or-sidebar-hooks-exist
  3. http://stackoverflow.com/search?q=wordpress+widget
share|improve this answer
add comment

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... :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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