add_action(), add_filter() before or after function

It is easier to read: When is what called? If you are debugging a hook you can immediately see if you have to read the function or not: If it is not your hook, you can skip the code.

In my themes and plugins I combine all registrations for actions, filters and shortcodes at the top and I add the hook to the PHPDoc block:

add_action( 'wp_head',  'foo' );
add_action( 'shutdown', 'bar' );

/**
 * Foo you!
 *
 * @wp-hook wp_head
 * @return  void
 */
function foo()
{
    print '<!-- foo -->';
}

Leave a Comment