This document discusses WordPress filters and provides examples of how they can be used. It begins by defining a filter as a function that takes a WordPress value, optionally modifies it, and returns the resulting value. It then explains the apply_filters() function and lists over 1,300 filter hooks in core. Examples are given for using filters to modify content in the editor, customize admin menu ordering, filter meta boxes and post types when deleting users. Front-end filters discussed include modifying post content, body classes, and excerpt length. The document concludes with filters useful for development like modifying plugins/themes listings and enabling post by email.
3. drewf.us/wcabq13
WHAT IS A FILTER?
A filter is a function that:
1.Takes a specific WordPress value
2. (maybe) modifies it
3. Spits the resulting value back out
7. drewf.us/wcabq13
ADDING OR REMOVING FILTERS
add_filter( 'hook_name', 'callback', #priority, #args );
– When removing a filter, the hook, callback and priority must
match exactly. Fails silently.
remove_filter( 'hook_name', 'callback', #priority );
– Define priority any time. Define the args count + 1 if
additional args are passed from the filter hook
8. drewf.us/wcabq13
ALLTOGETHER NOW
// $value is filterable
apply_filters( ‘hook_name’, $value, (optional) $args );
function callback( $value, $arg ) {
// do stuff
return $value;
}
add_filter( 'hook_name', 'callback', 10, 2 );