Do WordPress widget (or sidebar) hooks exist?

Viewed 20385

I'm trying to filter ALL widget output through a simple filter, but can't find any hooks and was hoping to be pointed in the right direction. Or possibly my efforts are not even possible?

My simple filter is something like this:

function clean_widget_output( $input ) {
    return str_replace( array( "\t", "\n", "\r" ), '', $input );
}

add_[FILTER OR ACTION]( 'need_a_hook', 'clean_widget_output', 99 );

Any ideas? I'm pretty new to PHP, but I can get around.

5 Answers

there are lots of hooks for wordpress widgets that aren't documented. The wordpress codex doesn't list them, for whichever reason (such as these hooks may change in the future and will break unexpectedly with new updates and versions)... so use these with extreme caution.

to find out what they are, there are at least 2 places to look:

<wordpress install directory>/wp-includes/default-filters.php
<wordpress install directory>/wp-includes/default-widgets.php

contained in those two files is a pretty good listing of all the hooks wordpress uses.

An example would be a filter for widgets is widget_title

again, use these with caution, they're not guaranteed to work past the specific version of the code you're looking at.

Related