Professional Documents
Culture Documents
WORDPRESS HOOKS
Designer, developer,
marketer, shit-talker, etc.
@buildcreate
@wilsonography
buildcreate.com
- T O M M C FA R L I N @ T U T S P L U S
• apply_filters() • do_action()
This is the hook. This is the hook.
• add_filter() • add_action()
This is what you use to tie into This is what you use to tie into
the hook. the hook.
F I LT E R S ACTIONS
• Though you can pass all kinds of arguments into your filter function, the only thing you
get back is the value of what you’re filtering. So for example if you’re using
‘the_content’ filter, and you have your function accept the post ID as well as the default
content argument, all you can safely return at the end of your function is the content.
• Actions don’t return any data, only true. Always true. Deal with it.
• Actions also allow you to pass “all” as the hook name to tie into every hook. Yikes.
• You can pass a class method like so: array( 'My_Class', ‘my_class_method’ ).
This is especially useful in plugin development when ofttimes your plugin has several
class methods.
function my_filter_function($content) {
$output = '<div>'.$content.'</div>';
return $output;
}
• add_meta_boxes - Action: used to add meta boxes to the WordPress edit screen. You’d then
probably wind up using the save_post action to validate the data before saving.
• wp_enqueue_scripts - Action: used to add styles and scripts to the front end. Used a lot in themes
and plugins. There’s also an admin and login version for adding styles and scripts to those areas.
• the_content, the_title, etc - Filter: used to modify the content and title respectively. There are also
filters to modify these in the editor on the backend of WordPress.
• wp_authenticate_user - Filter: used to tie into the authentication process and run your own
authentication function on the user’s login form submission.
• body_class - Filter: say you want to add some classes to the body based on various conditions
(assuming you’re using the body_class function in your template), you would use this hook in your
functions.php to handle that.
Experiment!
• ????
• Profit!
• http://codex.wordpress.org/Plugin_API/Action_Reference
• http://code.tutsplus.com/articles/the-beginners-guide-to-
wordpress-actions-and-filters--wp-27373
• http://www.zell-weekeat.com/wordpress-actions-and-filters/
• http://codex.wordpress.org/Plugin_API/Filter_Reference