Hooks Generator

Pick a hook and get a callback with the right signature — the parameter count, the priority and, for filters, the return value that stops you white-screening the site.

the-content.php
Saved just now
The hook
KindKnown core hook — signature filled in below
Filters the post content before it is displayed. Runs on every post render, so keep it cheap.
Callback
The default. Runs in registration order alongside other tens.
Parameters1 passed to the callback
1
BodyModify the value, then let the generator return it.
return $content; is appended automatically — a filter that returns nothing wipes the value.
Extras
Include the remove_ call
Adds a commented remove_action/remove_filter with the matching priority.
Skip in the admin
Adds an is_admin() early return so the callback only runs on the front end.
Paste into a plugin, an mu-plugin, or a functionality plugin.
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io).
/**
 * Filter the_content.
 *
 * @param string $content Post content.
 *
 * @return string Filtered value.
 */
function mytheme_append_signature( $content ) {
	if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
		return $content;
	}

	$content .= '<p class="signature">Thanks for reading.</p>';

	return $content;
}
add_filter( 'the_content', 'mytheme_append_signature' );

About this generator

WordPress Hooks Generator Online

Pick a hook, get a callback that actually fits it. This WordPress hooks generator writes the add_action() or add_filter() call together with a correctly signed function: the right parameter count, the right priority, and — for filters — the return line that stops a missing value from blanking your content.

Around thirty core hooks are built in with their real signatures, so typing save_post or pre_get_posts fills in the parameters and the accepted-args count for you, and the Reference tab shows the matching remove_action() / remove_filter() call. Free, no account, and everything is generated in your browser.

Reviewed Output tested on WordPress 6.8 · PHP 8.3

Why the WordPress hooks generator beats copying a callback from memory

Hook mistakes are quiet. A typo in the hook name never fires and never errors. An action hooked as a filter returns nothing and wipes the value. Asking for four arguments from a hook that passes two throws an ArgumentCountError on PHP 8, but only on the page where that hook runs. This generator checks all three before you paste anything.

A built-in signature reference

Around thirty core hooks — init, save_post, pre_get_posts, the_content, upload_mimes, cron_schedules and more — ship with their real parameter lists. Type or click one and the kind, the parameters and the accepted-args count fill themselves in.

Action or filter, checked against core

Hooking the_content as an action, or init as a filter, is flagged as an error with a one-click switch. Unknown hook names are flagged too, because a misspelled hook fails silently forever.

Argument counts that PHP 8 will accept

Ask for more parameters than the hook passes and you get an error, not a surprise: ArgumentCountError at runtime. One click clamps the count back to what core actually sends.

The return line written for you

Filters get return $value; appended automatically, and echoing inside a filter body raises a warning — printing from a filter dumps output wherever that filter happens to run, including in feeds and admin lists.

Guards for the hooks that need them

save_post without an autosave or revision check, pre_get_posts without is_admin() and is_main_query(), the_content without is_singular(), wp_get_current_user() on init — each is caught, and the pre_get_posts guard can be inserted for you.

Three callback styles, plus the way back out

Named function, anonymous closure or class method. Choose the closure and the generator reminds you it can never be unhooked; choose a named function and the Reference tab gives you the exact remove_action() / remove_filter() call with the matching priority.

How does the Hooks Generator work?

Four steps from a hook name to a snippet you can paste. Nothing is uploaded; the code is built in the page as you type.

  1. 01

    Name the hook

    Type it or pick one of the suggestion chips. A recognised core hook fills in whether it is an action or a filter, its parameters and how many of them your callback receives.

  2. 02

    Shape the callback

    Set the function name, the priority and the accepted argument count, then choose a named function, a closure or a class method. Parameter names, types and descriptions are all editable and feed the generated docblock.

  3. 03

    Write the body

    Put your logic in the body box. Optionally add the commented remove_ call, or an is_admin() early return so the callback only runs on the front end.

  4. 04

    Clear the checks and export

    Work through the Checks tab, then switch between snippet, functions.php and plugin-file output and copy or download the result.

Worked example — appending a signature to single posts

A the_content filter at the default priority, taking one argument. Note the guard clause and the generated return line: this is the whole snippet output, unedited.

/**
 * Filter the_content.
 *
 * @param string $content Post content.
 *
 * @return string Filtered value.
 */
function mytheme_append_signature( $content ) {
	if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
		return $content;
	}

	$content .= '<p class="signature">Thanks for reading.</p>';

	return $content;
}
add_filter( 'the_content', 'mytheme_append_signature' );

Priority 10 and a single argument are the defaults, so neither is printed. Change either one and the generator adds them to the add_filter() call in the correct order — priority first, accepted args second.

WordPress hooks — frequently asked questions

The questions that come up most often when hooking into WordPress core, themes and plugins.

What is the difference between an action and a filter in WordPress?

An action runs at a point in the request and returns nothing — you use it to do something, like registering a post type on init. A filter is handed a value and must return one, so it modifies data on its way past. Using add_action() on a filter means the value is discarded, which usually shows up as an empty title or empty content.

Why is my add_action() callback not firing?

Three causes cover almost every case. The hook name is misspelled, and WordPress never warns about a hook nothing fires. The add_action() call runs after the hook has already fired, so registering on init from inside a wp_footer callback does nothing. Or the callback name does not match the function name exactly, including its namespace or class prefix.

What does the priority number in add_action() do?

It sets the order callbacks run on the same hook: lower runs earlier, and 10 is the default. Callbacks with the same priority run in the order they were added. Needing a priority above 100 to win usually means another plugin is hooking the same thing late, and finding out which one is more durable than escalating the number.

Why do I get "Too few arguments" or ArgumentCountError from my hook?

The fourth argument of add_action() / add_filter() is how many parameters WordPress passes to your callback, and it defaults to 1. If your function signature declares three parameters but you did not raise that number, PHP 8 throws an ArgumentCountError. Asking for more than the hook actually provides fails the same way, so the number must match both your signature and the hook.

Can I remove a hook added by a plugin or theme?

Yes, if it was added as a named function or a static method: call remove_action() / remove_filter() with the identical hook name, callback and priority, from a point later than where it was added but before the hook fires. Anonymous closures cannot be removed at all — there is no handle to reference — which is the main reason to avoid them in distributed code.

Where should I put my hook code — functions.php or a plugin?

A child theme's functions.php is fine for presentation logic that belongs to that theme. Anything the site should keep after a redesign — post types, cron events, REST routes — belongs in a small plugin or an mu-plugin, because switching themes silently disables functions.php code. The generator offers all three output shapes for that reason.

Where do I paste the code from the Hooks generator?

You have three good options and one bad one. Best is a small site-specific plugin — the generator can output one for you, and it keeps working when you change theme. A code-snippets plugin is fine too. A child theme's functions.php works but ties the code to that theme. Never edit the parent theme: the next update overwrites it and your code is gone.

Can I use the generated code in client work or a commercial plugin?

Yes. The output is ordinary WordPress API calls that you configured — there is no licence attached to it and no attribution required. Use it in client sites, commercial plugins and themes, or products you sell. The generated file carries a short credit comment you are free to delete.

The other Core generators in the library, plus the WordPress tools most often used alongside this one.