Wordpress Simple Actions & Filters
Curse the gods, this simple functionality can seem complicated. I think its a combination of the terminology and word choice being so unhelpful. Do I
do a filter or action? What is a hook here? Or maybe I need to register it? It's all very vague, and I constantly forget.
Anyway, here's some pretty pictures instead. I've made it as basic as possible, more for remembering which one to use and where.
🧗🏻♀️ Basic Actions (does a task, returns nothing)
Plug in new code at a specific point.
- Once you've registered your action with a
my_action_namein functions.php or a plugin, you can now call it.
- Whenever the code gets to a
do_action('my_action_name'), it'll run the associated callback function
- No need to return anything.
🔗 Action Links:
🔍 Basic Filters (returns filtered data)
Pass in a value, change the value, pass new value back.
- Registered your filter with an
add_filterreferencing a callback function.
- Run the filter with the
- The callback function will take the passed value, change it and return it back. (filtering it)
- MUST return something (the new value).
🔗 Filter Links: