Understanding Wordpress Actions and Filters10th Feb 2014
Wordpress action and filter hooks are what makes Wordpress incredibly extendable. These hooks are very easy to use if someone else has already wrote them, and you just had to hook something in. Understanding how they work is another matter entirely.
In this post, I’m going to walk you through my personal understanding of Wordpress action and filer hooks after a few hours of experiments.
The Difference Between Actions and Filters
The main difference between actions and filters is the purpose they are used for and how they are declared and used. Here’s a quick summary.
When something has to be added
add_action(). used with
When something has to be changed
apply_filters(). used with
Not sure you get what I mean? Lets dive into some examples of creating and using actions and filters.
Creating Wordpress Actions
You can create a wordpress action with the following code.If you enjoyed this article, please tell a friend about it! Share it on Twitter. If you spot a typo, I’d appreciate if you can correct it on GitHub. Thank you!