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.

  • Please make your question more specific. We need to know what you didn’t understand after reading the Codex.
    – fuxia
    Commented Aug 18, 2012 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
    Commented Aug 18, 2012 at 19:48
  • Otto, sorry I posted it at both ends. But yes, am going through your piece.
    – vajrasar
    Commented Aug 18, 2012 at 21:15

2 Answers 2


Seeing that you've referenced 3 Genesis Developers, i'd like to answer this question using 2 Genesis code snippets as well as 2 WordPress examples of action hooks and filters.


Different template files in Genesis include hooks which simply enable you to execute PHP code in that position of the template.

Here's a visual guide which shows all the hooks included in Genesis.

If you look in the genesis > lib > framework.php file you'll find all the theme specific actions hooks which load when the loop loads.

do_action( 'genesis_after_loop' );

The above hook executes after the WordPress hook named loop_end. You can use any hook included in WordPress in Genesis as well as all the Genesis theme specific hooks.

Here's a very basic example of how to use both a WordPress and Genesis action hook in your child theme to add content in a specific position in your theme.

add_action( 'genesis_after_loop', 'add_text_after_loop' );
function add_text_after_loop() {
echo 'Hello World - Genesis After Loop Hook';

And here's a very similar WordPress hook you can use in Genesis or any other theme to display content after the loop.

add_action( 'loop_end', 'add_text_after_loop_end' );
function add_text_after_loop_end() {
echo 'Hello World - WordPress Loop End Hook';

To test these hooks, you could add both snippets to your child themes functions file to see exactly where the text 'Hello World' displays. Then you can change the hook to any other using the visual hook guide to determine the location you want to output the text.

enter image description here

You can see in the above that the Hello World text displays after the comment form for both hooks in the same position.


Different files in Genesis include filters which enable you to modify the default output of a parent themes function.

The code for a filter in Genesis looks like this:

$post_info = apply_filters( 'genesis_post_info', '[post_date] ' . __( 'by', 'genesis' ) . ' [post_author_posts_link] [post_comments] [post_edit]' );

The above line of code can be found in the genesis > lib > structure > post.php file.

This is the code which includes the filter named genesis_post_info which you can use in your child themes functions file to modify the post info for author, date, comments etc:

add_filter( 'genesis_post_info', 'sp_post_info_filter' );
function sp_post_info_filter($post_info) {
$post_info = '[post_date] by [post_author_posts_link] [post_edit]';
return $post_info;

In the above example, i have removed the shortcode for the comments link so only the date, author and edit links will be returned and displayed after the entry title.

This is a classic example of how you can use a filter to change the original function via your child theme without editing the default functions code in the parent theme.

This filter is only applicable in Genesis and not available in WordPress.

Here's an example of a custom function which works with both Genesis and any other theme as its included in the core WordPress files so works in any theme.

add_filter( 'excerpt_length', 'sp_excerpt_length' );
function sp_excerpt_length( $length ) {
return 50; // pull first 50 words

The above code enables you to modify the length of the post excerpt in any theme.

Source http://my.studiopress.com/snippets/


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.

  • Chip, thanks. Plus, am going through the link too.
    – vajrasar
    Commented Aug 18, 2012 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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