Find All Functions Attached to WordPress Filter & Action  Hooks

Quite often I encounter situations where it’s useful to know what functions are affecting a particular WordPress hook. It really helps me understand the ways that WordPress core, themes and plugins affect my site, specifically through the use of add_action() and add_filter(). This handy function make’s it pretty easy to discover what functions are attached to a given WordPress hook.

/**
 * Print Filters For
 *
 * Discover what functions are attached to a given hook in WordPress.
 */
function print_filters_for( $hook = null ) {
    global $wp_filter;

    // Error handling
    if ( !$hook )
        return new WP_Error( 'no_hook_provided', __("You didn't provide a hook.") );
    if ( !isset( $wp_filter[$hook] ) )
        return new WP_Error( 'hook_doesnt_exist', __("$hook doesn't exist.") );

    // Display output
    echo '<details closed>';
    echo "<summary>Hook summary: <code>$hook</code></summary>";
    echo '<pre style="text-align:left; font-size:11px;">';
    print_r( $wp_filter[$hook] );
    echo '</pre>';
    echo '</details>';
}

Usage

// Find all functions attached to 'the_content'
print_filters_for('the_content');

This will output the results into your environment like this:

<details closed>
    <summary>Hook summary: <code>the_content</code></summary>
    <pre style="text-align:left; font-size:11px;">
    Array
    (
        [11] => Array
            (
                [capital_P_dangit] => Array
                    (
                        [function] => capital_P_dangit
                        [accepted_args] => 1
                    )

                [do_shortcode] => Array
                    (
                        [function] => do_shortcode
                        [accepted_args] => 1
                    )

            )

        [10] => Array
            (
                [wptexturize] => Array
                    (
                        [function] => wptexturize
                        [accepted_args] => 1
                    )

                [convert_smilies] => Array
                    (
                        [function] => convert_smilies
                        [accepted_args] => 1
                    )

                [convert_chars] => Array
                    (
                        [function] => convert_chars
                        [accepted_args] => 1
                    )

                [wpautop] => Array
                    (
                        [function] => wpautop
                        [accepted_args] => 1
                    )

                [shortcode_unautop] => Array
                    (
                        [function] => shortcode_unautop
                        [accepted_args] => 1
                    )

                [prepend_attachment] => Array
                    (
                        [function] => prepend_attachment
                        [accepted_args] => 1
                    )

            )
    )
    </pre>
</details>

I’ve been using this myself for a while, hopefully someone else out there will find it useful.

Related Articles

Meet the Author

Kevin Leary, WordPress Consultant

I'm a custom WordPress web developer and analytics consultant in Boston, MA with 17 years of experience building websites and applications. View a portfolio of my work or request an estimate for your next project.