Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Well, am having a very hard time understanding the difference between Actions and Filters. I do use actions in my code, but am a rookie and I don't know even a slightest bit of Filters.

I have been to codex, and various sites by NickTheGeek, BillErickson, Gary Jones etc, but no vein.

If you can tell me in simple words, with example that what basically is and difference between actions, filters and hooks.

Thanks a ton.

share|improve this question
Please make your question more specific. We need to know what you didn’t understand after reading the Codex. –  toscho Aug 18 '12 at 19:15
Or just read the answers we already gave you on the support forums: wordpress.org/support/topic/actions-filters-and-hooks –  Otto Aug 18 '12 at 19:48
Otto, sorry I posted it at both ends. But yes, am going through your piece. –  vajrasar Aug 18 '12 at 21:15
add comment

2 Answers

up vote 3 down vote accepted

A filter filters content. An action executes an action.

For instance, post content is passed through a filter, e.g.:

echo apply_filters( 'the_content', $content );

That means that, if any filters are added, i.e. via add_filter( 'the_content', 'callback_name' ), the default $content is modified and returned by the specified callback.

An action, on the other hand, is simply a location where specified code is executed. For instance, wp_head is an action: a location in the template where code is executed (such as wp_enqueue_script(), etc.).

As usual, Otto has a great write-up that goes more in-depth.

share|improve this answer
Chip, thanks. Plus, am going through the link too. –  vajrasar Aug 18 '12 at 21:17
add comment

In my layman terms, Hooks as the name suggest is like placeholder where you can hook anything you want. To hook anything, you:

  1. Create function
  2. add_action('hookname','functionname');

For filters, the functions are already pre-built, but you want to edit and display a different one. So, first, you filter.

And FYI, to create a hook, you just:

  1. Create function with do_action e.g.

    function custom_hook() {
        echo 'Custom Hook works!';
  2. List item

    <?php custom_hook(); ?>
share|improve this answer
Not only that this is a bad advice (add global function that has hook in it - see here how to do it right - just add the hook directly in the template), it is also exactly the code from your question where you're telling that it's not working, right? –  kaiser Oct 14 '12 at 19:37
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.