If you want to return value when use add_filter in WordPress? When registering a filter(or basically calling apply_filters), you should call the function with at least two arguments – name of the filter to be applied and the value to which the filter will be applied.
Any further arguments that you pass to the function will be passed to the filtering functions, but only if they have requested additional arguments. Here’s an example:
1 2 3 4 5 6 7 8 9 | // Minimal usage for add_filter() add_filter( 'my_filter', 'my_filtering_function1' ); // We added a priority for our filter - the default priority is 10 add_filter( 'my_filter', 'my_filtering_function2', 11 ); // Full usage of add_filter() - we set a priority for our function and add a number of accepted arguments. add_filter( 'my_filter', 'my_filtering_function3', 12, 2 ); // Apply our custom filter apply_filters( 'my_filter', 'content to be filtered', 'argument 2', 'argument 3' ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.