In previous article we have covered the Action Hooks in WordPress. In this article we are about to explore the Filter Hooks in WordPress.
But before starting first have a look at difference between action hook and filter hooks.
Action Hooks can be executed on certain events while filter hooks executed for text and/or content manipulation. So let’s start with this article then.
Same as action hooks we are about to take official information rather than making our own definition.
Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.
As definition says Filter hooks are used to manipulate the text/content before being displayed on browser screen.
Let me know give you few examples for Filter Hooks in wordpress.
Usage of the Filter hook is same as action hook. Create function and hook that function to appropriate filter functions. That’s it.
I will give you some examples where we can see Filter Hook in working. :)
Very first we will use most used (as per me) Filter hook which is the_content.
Filter hooks are used to manipulate the text/content before being displayed on browser screen.
In this example we will add some fixed content to all posts content, Let’s have a look at below code block for the same.
In this example we will make all author name to UPPERCASE.
Isn’t it looks much easy? :) Yes it is, all you need to find is appropriate Hook for your need and you are done.
At the end we can say that Filter Hooks are used to manipulate the text/content of the post/page. What next? In next upcoming article we will create our own Hook.
If you don’t want to miss any upcoming article in this series then subscribe to our RSS Feed via mail, Like us on Facebook or Follow us no Twitter. If you do so, I am sure you will never miss any article/freebies or updates from us.
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash