Actually by that way you can't filter every widgets data. WordPress do not provides any native way to filter the final output of any widget. But there is some other way to modify any widget content and they are-
1. Modify the widget’s source files.
Obviously this is not a good method, as your modifications will be lost if WordPress, or the plugin creating the widget is updated.
2. Copy the widget into your own plugin or theme and modify it there.
3. Replace the widget’s original display callback function with a custom function, which then runs the original display callback function, but with filters.
Basically, the widget’s original display callback function is overridden with a new custom function, which runs the widget’s original callback function, but uses output buffering to capture the output, and run it through a filter before displaying it. I got it here Here is the code which can be used in a theme or plugin, which will provide a widget_output
filter, along with the widget type and unique widget ID as parameters:
First, we need to replace the widget’s original display callback function with a custom function of own:
function the_dramatist_filter_dynamic_sidebar_params( $sidebar_params ) {
if ( is_admin() ) {
return $sidebar_params;
}
global $wp_registered_widgets;
$widget_id = $sidebar_params[0]['widget_id'];
$wp_registered_widgets[ $widget_id ]['original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
$wp_registered_widgets[ $widget_id ]['callback'] = 'the_dramatist_custom_widget_callback_function';
return $sidebar_params;
}
add_filter( 'dynamic_sidebar_params', 'the_dramatist_filter_dynamic_sidebar_params' );
Next, we need to create the function referenced in the previous block of code, which will in turn run the widget’s original display callback function, but will capture its output using PHP output buffering. Then, the widget_output
filter will be run on the widget’s generated HTML markup, before being output to the page:
function the_dramatist_custom_widget_callback_function() {
global $wp_registered_widgets;
$original_callback_params = func_get_args();
$widget_id = $original_callback_params[0]['widget_id'];
$original_callback = $wp_registered_widgets[ $widget_id ]['original_callback'];
$wp_registered_widgets[ $widget_id ]['callback'] = $original_callback;
$widget_id_base = $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base;
if ( is_callable( $original_callback ) ) {
ob_start();
call_user_func_array( $original_callback, $original_callback_params );
$widget_output = ob_get_clean();
echo apply_filters( 'widget_output', $widget_output, $widget_id_base, $widget_id );
}
}
With that in place, you can do something like this in a plugin or theme, to modify the output of any widget:
function the_dramatist_widget_output_filter( $widget_output, $widget_id_base, $widget_id ) {
/* To target a specific widget ID: */
if ( 'target_widget_id' == $widget_id ) {
// Apply your desired search and replace operations here
}
return $widget_output;
}
add_filter( 'widget_output', 'the_dramatist_widget_output_filter', 10, 3 );
Hope the above helps.