Filters are one of the two types of Hooks.
They provide a way for functions to modify data of other functions.
You can filter any function that has applied a filter on it’s variables during the function definition.
For example, in the get_bloginfo
function, you would see a filter applied on it’s output just before the output is returned:
$output = apply_filters( 'bloginfo', $output, $show );
The above apply_filters call means you can modify the output by defining a filter such as:
function wpse253559_define_filter( $output, $show ) {
return 'altered';
}
add_filter( 'bloginfo', 'wpse253559_define_filter', 10, 2 );
This would alter the output of get_bloginfo
to always return “altered” no matter what it’s initial value is. You can read more on add_filter
and apply_filters
.
References: