WordPress Performance: Hook System: Advanced Customisation
9 minute read WordPress Performance · Part 3
Master actions, filters, priorities and custom hook creation for deeply flexible plugin and theme development in WordPress.
Hooks are the backbone of extensibility in WordPress. Mastering them lets you customise without modifying core code.
Here’s how to go beyond add_action() and add_filter() basics.
Actions do something:
add_action( 'init', 'register_custom_post_type' );
Filters modify and return something:
add_filter( 'the_title', 'prefix_title' );
Hooks accept priority and argument count:
add_filter( 'the_content', 'add_cta', 20, 1 );
add_filter( 'excerpt_more', 'custom_ellipsis', 10, 2 );
For inline logic:
add_action( 'wp_footer', function() {
echo '<!-- Tracking code -->';
});
Note: Harder to remove later.
Remove default behaviour:
remove_action( 'wp_head', 'wp_generator' );
Remove plugin logic conditionally:
remove_filter( 'the_content', 'some_plugin_output' );
Create your own in plugins or themes:
do_action( 'myplugin_before_form' );
And listen for them elsewhere:
add_action( 'myplugin_before_form', 'custom_notice' );
Use did_action() or current_filter() to introspect:
if ( did_action('init') ) { log_it('Init has run'); }
echo current_filter();
Plugins like Query Monitor can show live hook firing order.
prefix_hook_nameIn a modular theme refactor for a performance project: