Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.
For the best experience please use the latest Chrome, Safari or Firefox browser.
Use a spacebar or arrow keys to navigate
Erick Hitter
cdia@ethitter.com
In WordPress parlance, a hook is something that lets your plugin (or theme) interact with WordPress in a different way than functions and classes allow.
These interactions might let you modify how WordPress behaves, or change some value somewhere within WordPress.
Hundreds of these hooks are present throughout WordPress.
Convoluted explanation, no?
Think of these as similar to Javascript events.
init
after_setup_theme
the_title
the_author
Comprised of two functions:
do_action( $tag, $arg = '' )
add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 )
do_action()
$tag
– the name of the action that other code can hook to.$arg
– datum made available to the function that executes when this action is called.
Example:
do_action( 'after_setup_theme' );
add_action()
$tag
– the name of the action to hook to.$function_to_add
– the name of the function to execute when the action fires.$priority
– an integer indicating this function's priority. Default is 10. Lower numbers execute sooner.$accepted_args
– how many arguments is your function expecting. Hint: can't be more than the action provides.
Example:
/** * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run. */ add_action( 'after_setup_theme', 'twentyeleven_setup' );
Comprised of two functions:
apply_filters( $tag, $value )
add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 )
Look familiar?
apply_filters()
$tag
– the name of the filter to hook to.$value
– the value to be filtered.
Example:
$excerpt_length = apply_filters('excerpt_length', 55);
add_filter()
$tag
– the name of the filter to hook to.$function_to_add
– the name of the function to execute when the filter fires.$priority
– an integer indicating this function's priority. Default is 10. Lower numbers execute sooner.$accepted_args
– how many arguments is your function expecting. Hint: can't be more than the filter provides.
Example:
add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
Actions |
Filters |
---|---|
Do something | Change something |
Provide data for use in the function, but don't take it back. | Provide a value to be modified and must get something back. |
Can echo things within. | Never echo things within. |