158 PART II • Designing and Developing WordPress Themes
Just put in your intended hook name and put the code wherever you want it in your theme. If
you have a hook named 'welcome_front', that means you’ll put the following wherever
you want to be able to hook on to the welcome_front() hook:
<?php do_action( 'welcome_front' ); ?>
To hook on to your custom hook, just use the add_action() function as you did previ-
ously. In fact, wp_head() and wp_footer() are really just wrappers for do_action(
'wp_head' ) and do_action( 'wp_footer' ), so it is really the same.
To recap: add_action() is used to add functions to hooks, most likely in functions.php,
whereas do_action() creates your own hooks and resides in your theme files.
REMOVING ACTIONS FROM HOOKS
If you’re working with a child theme that uses a parent theme with a lot of hooks, you might
want to remove functionality. There are several alternatives here, depending on the situation,
but they all work more or less the same. Say that you want to remove an action attached to
wp_meta() with add_action(); you would use remove_action(). For example, say
the parent theme has the following code snippet, which adds the function superfunction
to wp_meta():
add_action( 'wp_meta', 'superfunction' );
Now you don’t want that, so you’ll use remove_action() to remove it:
remove_action( 'wp_meta', 'superfunction' );
That’s it! What’s important to remember is that you need to be specific about what you want
to remove, and if you have passed additional information in add_action() when adding
the action, you need to pass it to remove_action() as well. Remember that when you are
removing with hooks, you are removing the function attached to the action, not the action
itself — which is why the call to remove_action needs a function alongside it.
The remove_filter() tag works the same, but for filters.
USING TAXONOMIES
Taxonomies are both cool and useful. Basically, they enable you to create your very own
versions of categories or tags. This means that you can have several different sets of tags, for
example. Just to get the lingo straight right away: A taxonomy has terms associated with it.
The tags in the standard Tags taxonomy are in fact terms, as are the categories in the default
Categories taxonomy.
By adding taxonomies, you add more ways to organize and classify your posts. You could say
that the default categories and tags are both taxonomies that are there by default, so you have
one taxonomy called Categories and one called P o s t Ta g s to start with. Suppose you want