Is there any filter which can be used in a plugin to process the content of the text widget before it is rendered?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Filter
- widget_text (for the text)
- 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
- http://codex.wordpress.org/WordPress_Widgets
- https://stackoverflow.com/questions/1385954/do-wordpress-widget-or-sidebar-hooks-exist
- https://stackoverflow.com/search?q=wordpress+widget
Method 2
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… 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0