When was the last time a conference session presenter asked for, and received a Stephen Colbert-like applause at the beginning of their presentation?
It happened last weekend when Mike Stowe spoke on WordPress hooks at WordCamp Orlando 2013.
One of the most entertaining talks I enjoyed at WordCamp Orlando 2013, Mike included references to pirates, foxes, Elvis Presley, The Matrix, and dinosaurs as he explained what hooks are, types of hooks, how they work, and what to consider as you write code for hooks.
Check out Mike’s slides, my key takeaways, and some of the backchannel conversation from his presentation.
Key Takeaways
- A hook is an event
- Filters allow you to modify content. Actions allow you to add and remove code.
- Priority matters; a lower number is higher priority than a higher number.The default priority is 10.
- Avoid conflicts, make sure you have unique names for your function
- Filter hooks are called when processing content, whether it be for saving or rendering
- Filter hooks are added using the add_filter() function
- The syntax for a Filter hook is
add_filter( $tag, $function, [$priority], [$accepted_arts] );
- Action hooks are added using the add_action() function
- Action hook is triggered when action event takes place. Example: loading a page, inserting comments, saving blog posts.
- The syntax for an Action hook:
add_action( $hook, $function_to_add, $priority, $accepted_args );
- Setup Custom hooks using the do_action() and apply_filters() functions
do_action('hook_name');
apply_filters('hook_name', $content);
- Use the Codex to learn more about Filter and Action hooks
Backchannel
https://twitter.com/redcrew/status/402165524526039040
http://twitter.com/redcrew/status/402174266864836608
https://twitter.com/redcrew/status/402170819297943553
http://twitter.com/AdamSoucie/status/402184493542699010