YogeshChauhan.com
apply_filters function in WordPress
February 20, 2021

In this post, we saw the add_filter hook and how to use that to add functions to your WordPress code.

applt_filters calls the functions that have been added to the filter hook.

Even after adding the functions, the job is not done. We need to call those functions. Those functions attached to the filter hook are invoked by calling applt_filters function.

Syntax


apply_filters($tag, $value )

Where the $tag is required as a string variable — it’s the name of the filter hook.

and the second parameter $value is mixed – these are the values to filter.

We can call applt_filters function to create a new filter hook. To do so, we need to call applt_filters function with the name of the new hook that was specified using the $tag parameter.

Using applt_filters function, we can also pass multiple arguments to hooks.

Example


// The filter callback function.
function concat( $str, $str1, $str2) {
    $str .= $str1 . $str2
    return $str;
}
add_filter( 'concat_filter', 'concat', 10, 3 );

In the example above, concat_filter is the hook. We apply the filters by calling the concat() function that’s hooked onto concat_filter above. We are passing the additional arguments as $str1 and $str2.

The last two parameters in add_filter, 10 and 3 are very important. 10 is the priority and 3 is the number of the parameters.

Credit: WordPress Developers

dreamhost

Leave a Reply

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to set opacity or transparency using CSS? #3 Pagination in CSS with multiple examples #4 How to make HTML form interactive and using CSS? #5 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

Mar 5 How to create flickering text using CSS? Mar 4 How to use data-* Attributes in HTML? Mar 4 The substr() method in JavaScript and how it’s different from substring() Mar 4 A complete guide to add responsive YouTube videos using HTML and CSS Mar 3 How to embed YouTube or other video links in WordPress? Mar 3 How to change the Login Logo in WordPress?

You might also like these

Learn to create profile card using HTML and CSSCSSCan Firewall and IDPS Stop DDoS Attack?MiscEverything you need to know about ANY, SOME and ALL Operators in PostgresPostgresFew more :nth-child examples in CSSCSSHow to Sort (Shuffle) an Array in Random Order in JavaScript?JavaScriptHow to change HTML content on click using JavaScript?JavaScript