How to Find WordPress Hooks (Actions and Filters)

How to Find WordPress Hooks (Actions and Filters)

WordPress hooks are the safe way to customize WordPress, WooCommerce, or a theme without editing core or plugin files. They come in two kinds, actions and filters, and the trick to customizing anything is finding the right one to attach to. Here is how they work and how to find them.

Actions vs filters

Both let your code run at a specific point, but they do different jobs.

  • Actions run code at a moment in the page lifecycle and do not return anything. You register them with add_action(), and core fires them with do_action(). Use an action to send an email, enqueue a script, or insert markup.
  • Filters receive a value, modify it, and must return it. You register them with add_filter(), and core fires them with apply_filters(). Use a filter to change a title, tweak content, or adjust a price.

The one rule that trips people up: a filter callback must return a value. Forget the return and you wipe out whatever you were trying to change.

How to find WordPress hooks

There are three reliable ways to discover the hook you need.

  1. Check the reference. The official Code Reference lists core actions and filters with their arguments. WooCommerce and big plugins publish their own hook docs too.
  2. Search the source. Grep the plugin or theme files for do_action( and apply_filters(. Every hook is declared there, so the source is the source of truth when docs are thin.
  3. Use a hook finder. Paste a hook name into the WordPress Hook Finder to confirm whether it is an action or a filter and see how to wire it up. It runs entirely in your browser, so nothing you paste leaves your device.

Priority and accepted arguments

When you register a callback, two extra arguments matter:

  • Priority controls order. The default is 10. A lower number runs earlier, a higher number runs later. Set priority when another callback is fighting yours.
  • Accepted args tells WordPress how many parameters to pass your function. The default is 1. If a hook offers more, raise this number to receive them.
// Action: add a note after WooCommerce checkout.
add_action( 'woocommerce_thankyou', 'mysite_after_checkout', 10, 1 );
function mysite_after_checkout( $order_id ) {
	error_log( 'Order completed: ' . $order_id );
}

// Filter: change the excerpt length. Must return the value.
add_filter( 'excerpt_length', 'mysite_excerpt_length', 20 );
function mysite_excerpt_length( $length ) {
	return 30;
}

Notice the action returns nothing while the filter returns the modified value. That is the whole difference in two snippets.

Why hooks instead of editing files

Editing core or a plugin directly means your changes vanish on the next update. Hooks let you extend behavior from your own theme or a small plugin, so updates stay safe and your customizations survive. Find the hook with the WordPress Hook Finder, drop your callback in a child theme or snippet, and you are done.

Find the right hook, return the value when it is a filter, and you can bend WordPress to your will without touching a single core file.

← All posts