WordPress Hooks Index
A searchable index of WordPress actions and filters: the add_action or add_filter signature, when each fires, the source line, examples and common mistakes.
64 hooks, each with its add_action or add_filter signature, when it fires and the file and line that call it. Most also have a code example and a note on the mistake that catches people out.
Every entry was read from the WordPress 7.1.4 and WooCommerce 11.2.2 source on 2026-11-16. The examples were checked against that source. Most were not run on a site; where an entry says “in our test”, that behaviour was run in WordPress Playground on the date given. WordPress has thousands of hooks; this is a selection for everyday theme and plugin work.
An action runs your callback at a set point and ignores what it returns; a filter passes your callback a value and uses whatever it returns. In a signature such as add_filter( 'style_loader_tag', 'my_callback', 10, 4 ), 10 is the priority (lower numbers run first, and 10 is the default) and 4 is how many arguments your callback receives (the default is 1).
Lifecycle 5
Runs once WordPress, the active plugins and the theme have loaded and the current user is set, before any output. The standard place to register post types, taxonomies, shortcodes and rewrite rules.
Fires
On every request (front end, admin, admin-ajax.php, REST API and WP-Cron), after after_setup_theme and before wp_loaded.
Signature
add_action( 'init', 'my_callback' );Example
add_action( 'init', function () {
register_post_type( 'book', array(
'public' => true,
'label' => 'Books',
'show_in_rest' => true, // required for the block editor
) );
} );The gotcha
Because it runs on every request, including AJAX, REST API and cron requests, a slow callback (a remote HTTP call, an uncached query) slows all of them. Nothing has been sent to the browser yet, so anything you echo here goes out before the headers and stops later redirects and cookies from working.
Called in
wp-settings.php:779 (WordPress 7.1.4)
Runs once the active theme's functions.php files have loaded. The usual place for add_theme_support(), add_image_size() and register_nav_menus().
Fires
After the child theme's functions.php and then the parent's have loaded, before init.
Signature
add_action( 'after_setup_theme', 'my_callback' );Example
add_action( 'after_setup_theme', function () {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
add_image_size( 'card', 600, 400, true ); // true = hard crop
} );The gotcha
With a child theme, the child's functions.php loads first, so at the same priority the child's callback runs before the parent's. add_image_size() simply overwrites any size with the same name. If the parent registers 'card' in its own after_setup_theme callback at priority 10, a child that redefines 'card' at priority 10 loses. Give the child's callback a later priority, such as 11.
Called in
wp-settings.php:757 (WordPress 7.1.4)
Runs once every active plugin file has been included. The earliest point where you can safely check for, or extend, another plugin.
Fires
After all plugins and the pluggable functions have loaded, before the theme's functions.php.
Signature
add_action( 'plugins_loaded', 'my_callback' );The gotcha
wp_get_current_user() works here, but calling it makes WordPress work out the user before the theme has loaded, so a determine_current_user filter added by the theme never gets a say. Translating a string from your own text domain this early (a __() call, for example) makes WordPress load the translations too soon, and since 6.7.0 that raises a _doing_it_wrong notice asking for init or later. If you need the user or translated text, wait for init.
Called in
wp-settings.php:630 (WordPress 7.1.4)
Runs once WordPress, the plugins and the theme are fully loaded and init has finished.
Fires
Right after init on every request. On the front end it fires before the main query runs.
Signature
add_action( 'wp_loaded', 'my_callback' );Called in
wp-settings.php:801 (WordPress 7.1.4)
Runs on admin requests once the admin code has loaded, before any admin output. Used for register_setting(), capability checks and admin-side redirects.
Fires
On wp-admin screens it fires from admin.php after the login check and after the admin menu is built, so after admin_menu. admin-ajax.php and admin-post.php fire it too, before they run their action handlers, and for logged-out visitors as well.
Signature
add_action( 'admin_init', 'my_callback' );The gotcha
admin-ajax.php fires it too, and front-end AJAX goes through admin-ajax.php. Code that assumes an admin screen, such as a redirect to your settings page, also runs inside those AJAX calls and breaks them. Check wp_doing_ajax() first.
Called in
wp-admin/admin.php:180 (WordPress 7.1.4)
Enqueue & assets 11
The hook for enqueueing front-end stylesheets and scripts with wp_enqueue_style() and wp_enqueue_script().
Fires
On front-end requests, from wp_head at priority 1, before WordPress prints the enqueued styles (wp_print_styles, priority 8) and head scripts (wp_print_head_scripts, priority 9).
Signature
add_action( 'wp_enqueue_scripts', 'my_callback' );Example
add_action( 'wp_enqueue_scripts', function () {
// Child theme: load your style.css after the parent's stylesheet.
wp_enqueue_style(
'child-style',
get_stylesheet_uri(),
array( 'parent-theme-style' ), // the handle the PARENT registers; check its functions.php
wp_get_theme()->get( 'Version' ) // cache-bust on version change
);
} );The gotcha
It covers stylesheets too; there is no wp_enqueue_styles hook. It does not fire in wp-admin (use admin_enqueue_scripts), on wp-login.php (use login_enqueue_scripts) or for the block editor's interface (use enqueue_block_editor_assets). If a dependency handle is not registered when styles print, WordPress leaves out the file that depends on it. In 7.1.4 it reports this as a _doing_it_wrong notice, which you only see with WP_DEBUG on.
Called in
wp-includes/script-loader.php:2340 (WordPress 7.1.4)
Enqueue CSS and JavaScript in wp-admin. Receives the current screen's hook suffix, so you can load files on one screen only.
Fires
On wp-admin screens, from admin-header.php, inside the admin <head>, just before admin_print_styles and admin_print_scripts print the queued styles and scripts.
Signature
add_action( 'admin_enqueue_scripts', 'my_callback' ); // receives $hook_suffixExample
add_action( 'admin_enqueue_scripts', function ( $hook ) {
if ( 'settings_page_my-plugin' !== $hook ) {
return; // do not load our JS on every admin screen
}
wp_enqueue_script( 'my-admin', plugins_url( 'admin.js', __FILE__ ), array(), '1.0', true );
} );The gotcha
Check $hook_suffix before enqueueing. Files loaded on every admin screen can clash with other plugins' scripts and styles on screens you never meant to touch. A page added with add_options_page() has a suffix of the form settings_page_{menu_slug}.
Called in
wp-admin/admin-header.php:123 (WordPress 7.1.4)
Enqueue scripts and styles for the block editor's interface, such as block registration scripts and sidebar panels. Nothing loads on the front end or on other admin screens.
Fires
When the post editor, the Site Editor, the block widgets screen or the Customizer's block widgets load.
Signature
add_action( 'enqueue_block_editor_assets', 'my_callback' );Called in
wp-admin/edit-form-blocks.php:357 (WordPress 7.1.4)
Enqueue files that must load both in the block editor and on the front end, typically the shared styles a block needs to look the same in each.
Fires
On front-end requests and when the block editor loads its content.
Signature
add_action( 'enqueue_block_assets', 'my_callback' );Example
add_action( 'enqueue_block_assets', function () {
wp_enqueue_style(
'my-block-shared',
plugins_url( 'block.css', __FILE__ ),
array(),
'1.0'
);
} );The gotcha
It runs in both places, so a script enqueued here also runs inside the editor, and editor-only code ends up on the public site. Use enqueue_block_editor_assets for editor-only code and wp_enqueue_scripts for front-end-only code.
Called in
wp-includes/script-loader.php:2527 (WordPress 7.1.4)
Enqueue CSS and JavaScript on wp-login.php: the login, registration and lost-password screens.
Fires
In the <head> of wp-login.php, just before login_head.
Signature
add_action( 'login_enqueue_scripts', 'my_callback' );Example
add_action( 'login_enqueue_scripts', function () {
wp_enqueue_style(
'my-login',
get_stylesheet_directory_uri() . '/login.css',
array(),
wp_get_theme()->get( 'Version' )
);
} );The gotcha
Neither wp_enqueue_scripts nor admin_enqueue_scripts fires on wp-login.php, which is why a login style added the usual way never appears. The theme's functions.php does load there, but the theme's stylesheet and templates do not, so rules your CSS inherits from the theme are missing.
Called in
wp-login.php:120 (WordPress 7.1.4)
Prints output into the <head>. Used for meta tags and small inline styles.
Fires
Inside <head> on the front end. Block themes get it from core's template-canvas.php; classic themes call wp_head() in their header template.
Signature
add_action( 'wp_head', 'my_callback' );The gotcha
Use it to print tags, not to load files. Enqueue CSS and JavaScript on wp_enqueue_scripts so WordPress can handle dependencies, versions and duplicates. A <script> tag echoed here loads even when the same library is already enqueued.
Called in
wp-includes/general-template.php:3441 (WordPress 7.1.4)
Filters the complete HTML for one enqueued script before it prints. Use it for attributes core has no argument for, such as crossorigin or integrity.
Fires
When WP_Scripts prints each enqueued script, in the head or the footer.
Signature
add_filter( 'script_loader_tag', 'my_callback', 10, 3 ); // receives $tag, $handle, $srcExample
add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
if ( 'my-cdn-lib' !== $handle ) {
return $tag; // only touch your own handle
}
return str_replace( ' src=', ' crossorigin="anonymous" src=', $tag );
}, 10, 3 );The gotcha
For defer and async there is a supported route since WordPress 6.3: pass array( 'strategy' => 'defer' ) as the last argument of wp_register_script() or wp_enqueue_script(). Core then checks the scripts that depend on it before applying it, which a string replace here skips. $tag also contains the script's translations and its inline before/after blocks, so a replace can hit those too. Always compare $handle first, or the change applies to every script on the page, jQuery included.
Called in
wp-includes/class-wp-scripts.php:496 (WordPress 7.1.4)
Filters the full <link rel='stylesheet'> tag before it prints. Used to add attributes, or to load a non-critical stylesheet without blocking rendering.
Fires
When WP_Styles prints each enqueued stylesheet.
Signature
add_filter( 'style_loader_tag', 'my_callback', 10, 4 ); // receives $tag, $handle, $href, $mediaExample
add_filter( 'style_loader_tag', function ( $tag, $handle ) {
if ( 'my-nonessential' !== $handle ) {
return $tag;
}
return str_replace( "media='all'", "media='print' onload=\"this.media='all'\"", $tag );
}, 10, 4 );The gotcha
Core writes the media attribute with single quotes (media='all'), so a str_replace that looks for media="all" matches nothing and it looks as if the filter never ran. Match the actual output, or build the tag yourself.
Called in
wp-includes/class-wp-styles.php:225 (WordPress 7.1.4)
Runs while WordPress registers its bundled scripts, so you can change a core-registered handle (its source, version or dependencies) before anything uses it.
Fires
Once per request, when the WP_Scripts object is first created.
Signature
add_action( 'wp_default_scripts', 'my_callback' ); // receives WP_Scripts $scripts (by reference)Example
add_action( 'wp_default_scripts', function ( $scripts ) {
if ( is_admin() ) {
return; // leave admin scripts alone
}
// Drop jQuery Migrate from the jquery bundle.
if ( ! empty( $scripts->registered['jquery'] ) ) {
$scripts->registered['jquery']->deps = array_diff(
$scripts->registered['jquery']->deps,
array( 'jquery-migrate' )
);
}
} );The gotcha
It fires only once, when something first calls wp_scripts(). If any code does that before your add_action() line runs, the hook has already fired and your callback never runs, so register it directly in the plugin's main file or the theme's functions.php, not inside another hook. Change $scripts in place; it is passed by reference and the return value is ignored. Without the is_admin() check the change also applies to every admin screen, where other plugins may still need jQuery Migrate.
Called in
wp-includes/class-wp-scripts.php:170 (WordPress 7.1.4)
Filters the URLs WordPress prints as resource hints (dns-prefetch, preconnect, prefetch, prerender) in the head.
Fires
On wp_head at priority 2 and on wp-login.php, once for each relation type.
Signature
add_filter( 'wp_resource_hints', 'my_callback', 10, 2 ); // receives $urls, $relation_typeExample
add_filter( 'wp_resource_hints', function ( $urls, $relation_type ) {
if ( 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin' => 'anonymous',
);
}
return $urls;
}, 10, 2 );The gotcha
The same callback runs four times per page, once per relation type, so check $relation_type or your URL ends up in every list. Entries can be plain URL strings or arrays with an href key (plus as, crossorigin, pr or type); an array without href is skipped. Core's own dns-prefetch list holds the hosts of enqueued scripts and styles that are served from other domains.
Called in
wp-includes/general-template.php:3907 (WordPress 7.1.4)
Content 4
Filters post content right before it is displayed. The usual place to append or prepend markup to a post.
Fires
Each time the_content() runs, and also when WordPress renders content for REST API responses, feeds, generated excerpts and the Post Content block.
Signature
add_filter( 'the_content', 'my_callback' ); // receives $contentExample
add_filter( 'the_content', function ( $content ) {
if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
return $content; // the guard that is easy to forget
}
return $content . '<p class="cta">Enjoyed this? Read more.</p>';
} );The gotcha
It runs far more often than the single-post view: once per post on archives, in feeds, for content.rendered in REST API responses (which the block editor requests), and inside wp_trim_excerpt() when WordPress builds an excerpt. Without the is_singular / in_the_loop / is_main_query guard, a call to action meant for single posts also appears on the blog index and in the RSS feed.
Called in
wp-includes/post-template.php:256 (WordPress 7.1.4)
Filters a post title before it is displayed.
Fires
Each time the_title() or get_the_title() runs.
Signature
add_filter( 'the_title', 'my_callback', 10, 2 ); // receives $title, $post_idThe gotcha
It also runs for titles in nav menus, page lists, the admin post list and title.rendered in REST API responses, so an unconditional change shows up in all of them. The document <title> in the browser tab is built with single_post_title instead, so this filter does not change it. Check in_the_loop() or the post ID before changing anything.
Called in
wp-includes/post-template.php:174 (WordPress 7.1.4)
Sets how many words an automatic excerpt contains. The default is 55, a translatable value, so some languages use a different number.
Fires
When wp_trim_excerpt() builds an excerpt for a post with no manual excerpt. The Latest Posts block applies it too.
Signature
add_filter( 'excerpt_length', 'my_callback' ); // receives $length (words)Example
add_filter( 'excerpt_length', function ( $length ) {
return 25;
}, 999 ); // late priority: the callback that runs last winsThe gotcha
Posts with a manual excerpt ignore it; WordPress shows those as written. If a theme or plugin also sets it, the callback that runs last wins, so use a late priority such as 999. A priority above 20 also overrides the Latest Posts block: while it renders, core adds its own callback at priority 20 to apply the block's word count, so your number replaces that setting and can change whether the block adds its Read more link. Use a priority below 20 if the block should keep its own count.
Called in
wp-includes/formatting.php:4081 (WordPress 7.1.4)
Changes the string added to the end of a shortened excerpt. The default is " […]".
Fires
Each time wp_trim_excerpt() builds an automatic excerpt. The string is only added if the text was cut.
Signature
add_filter( 'excerpt_more', 'my_callback' ); // receives $moreCalled in
wp-includes/formatting.php:4090 (WordPress 7.1.4)
Posts & queries 9
Changes a query's variables before it runs. The usual way to change what an archive, the search results or the blog index shows, without running a second WP_Query.
Fires
In WP_Query::get_posts(), after the query vars are parsed and before the SQL is built. It runs for every WP_Query, including the ones get_posts() makes.
Signature
add_action( 'pre_get_posts', 'my_callback' ); // receives WP_Query $query (by reference)Example
add_action( 'pre_get_posts', function ( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return; // both checks matter
}
if ( $query->is_category() ) {
$query->set( 'posts_per_page', 12 );
}
} );The gotcha
It runs in the admin too, and for every query on the page: menus, widgets, the media library and REST API requests. Without the is_admin() and $query->is_main_query() checks, a change meant for the blog index also changes the admin post list. Use the $query methods ($query->is_category()) rather than the global is_category(), and change the query with $query->set(); the return value is ignored.
Called in
wp-includes/class-wp-query.php:1916 (WordPress 7.1.4)
Filters the raw SQL WHERE clause of a query.
Fires
While WP_Query assembles its SQL.
Signature
add_filter( 'posts_where', 'my_callback', 10, 2 ); // receives $where, WP_Query $queryThe gotcha
This is raw SQL. Check $query->is_main_query(), and pass anything that came from a request through $wpdb->prepare(), or you open the site to SQL injection. get_posts() sets suppress_filters to true, so this filter does not run for get_posts() calls.
Called in
wp-includes/class-wp-query.php:2796 (WordPress 7.1.4)
Filters every SQL clause of a query at once (where, join, orderby, groupby, distinct, fields and limits) as one array. Use it instead of posts_where when a JOIN and an ORDER BY have to agree with each other.
Fires
While WP_Query assembles its SQL, after the individual clause filters.
Signature
add_filter( 'posts_clauses', 'my_callback', 10, 2 ); // receives array $clauses, WP_Query $queryExample
add_filter( 'posts_clauses', function ( $clauses, $query ) {
if ( is_admin() || ! $query->is_main_query() || ! $query->is_post_type_archive( 'book' ) ) {
return $clauses;
}
global $wpdb;
$clauses['join'] .= " INNER JOIN {$wpdb->postmeta} pm ON pm.post_id = {$wpdb->posts}.ID AND pm.meta_key = 'rating' ";
$clauses['orderby'] = ' pm.meta_value+0 DESC ';
return $clauses;
}, 10, 2 );The gotcha
get_posts() sets 'suppress_filters' => true by default, so this filter, posts_where, posts_join and the_posts never run for it. Code that works in new WP_Query() and does nothing in get_posts() is usually this, not a caching problem. Pass 'suppress_filters' => false, or use WP_Query directly. And prepare anything that came from a user: this is raw SQL.
Called in
wp-includes/class-wp-query.php:3032 (WordPress 7.1.4)
Filters the array of post objects a query returned, after the SQL has run. Used to reorder, drop or add posts in PHP when SQL cannot express what you need.
Fires
At the end of WP_Query::get_posts(), once the results are fetched.
Signature
add_filter( 'the_posts', 'my_callback', 10, 2 ); // receives array $posts, WP_Query $queryExample
add_filter( 'the_posts', function ( $posts, $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return $posts;
}
return array_values( array_filter( $posts, function ( $p ) {
return ! get_post_meta( $p->ID, 'hidden', true );
} ) );
}, 10, 2 );The gotcha
Removing posts here does not update $query->found_posts, so pagination still counts the ones you dropped: page 2 shows fewer items and the last page can come back empty. Exclude them in pre_get_posts instead, so the database does the counting. Like posts_clauses, it is skipped by get_posts() unless you set 'suppress_filters' => false.
Called in
wp-includes/class-wp-query.php:3641 (WordPress 7.1.4)
Filters the total number of posts a query found, which is what pagination is calculated from.
Fires
After the query runs, before the number of pages is worked out.
Signature
add_filter( 'found_posts', 'my_callback', 10, 2 ); // receives $found_posts, WP_Query $queryThe gotcha
It does not run when the query sets 'no_found_rows' => true or returns no posts, because WordPress skips the count. Unlike posts_where, suppress_filters does not switch it off.
Called in
wp-includes/class-wp-query.php:3735 (WordPress 7.1.4)
Filters the post row array just before WordPress writes it to the database. The hook for changing post_title, post_content, post_status or post_name on the way in; by the time save_post runs, the row is already saved.
Fires
Inside wp_insert_post(), after sanitising, before the INSERT or UPDATE query. Attachments go through wp_insert_attachment_data instead.
Signature
add_filter( 'wp_insert_post_data', 'my_callback', 10, 4 ); // receives $data, $postarr, $unsanitized_postarr, $updateExample
add_filter( 'wp_insert_post_data', function ( $data, $postarr ) {
if ( 'post' === $data['post_type'] && '' === trim( $data['post_title'] ) ) {
$data['post_title'] = 'Untitled ' . current_time( 'Y-m-d' );
}
return $data;
}, 10, 2 );The gotcha
$data arrives slashed, and core runs wp_unslash() on it after your filter returns. If you unslash it yourself, it is unslashed twice and literal backslashes in the content (code samples, Windows paths, regular expressions) disappear. Pass any new value that may contain backslashes through wp_slash(). It also fires for revisions and autosaves, so check $data['post_type'] before changing anything.
Called in
wp-includes/post.php:4978 (WordPress 7.1.4)
Runs after a post and its meta and terms have been saved. The dependable place to react to a finished save. WordPress 5.6 and later.
Fires
At the end of wp_insert_post(), after save_post. For REST API saves, which is how the block editor saves, core fires it only after the post's terms and meta are written.
Signature
add_action( 'wp_after_insert_post', 'my_callback', 10, 4 ); // receives $post_id, WP_Post $post, $update, $post_beforeExample
add_action( 'wp_after_insert_post', function ( $post_id, $post, $update, $post_before ) {
if ( 'post' !== $post->post_type || wp_is_post_revision( $post_id ) ) {
return;
}
// Safe: meta is written by now.
$price = get_post_meta( $post_id, 'price', true );
}, 10, 4 );The gotcha
The block editor saves through the REST API, which writes the post row first (firing save_post) and the meta and terms afterwards. So get_post_meta() inside save_post returns the previous value, and the meta always looks one save behind. Read meta here instead.
Called in
wp-includes/post.php:6021 (WordPress 7.1.4)
Runs on every post save and gives you both the old and the new status. The hook to use for "do something the first time a post is published".
Fires
During wp_insert_post(), after the row is written.
Signature
add_action( 'transition_post_status', 'my_callback', 10, 3 ); // receives $new_status, $old_status, WP_Post $postExample
add_action( 'transition_post_status', function ( $new, $old, $post ) {
if ( 'publish' !== $new || 'publish' === $old ) {
return; // already published: this is just an edit
}
if ( 'post' !== $post->post_type ) {
return;
}
my_send_new_post_notification( $post->ID );
}, 10, 3 );The gotcha
Every save of a published post fires it as publish to publish. Skip the 'publish' === $old check and a "new post" email goes out each time someone fixes a typo. A post created in the editor starts life as an auto-draft, so its first publish arrives as auto-draft or draft to publish; $old_status is 'new' only when wp_insert_post() creates a post without an ID. It fires for revisions and every post type, so check $post->post_type.
Called in
wp-includes/post.php:5922 (WordPress 7.1.4)
A dynamic action built from the new status and the post type, so you can hook one status and post type combination without a callback full of if statements.
Fires
Right after transition_post_status and {$old_status}_to_{$new_status}, during the same save.
Signature
add_action( 'publish_post', 'my_callback', 10, 3 ); // dynamic: publish_page, publish_book, draft_post… receives $post_id, WP_Post $post, $old_statusExample
// Fires for a custom post type 'book' entering publish.
add_action( 'publish_book', function ( $post_id, $post, $old_status ) {
if ( 'publish' === $old_status ) {
return; // an edit to a book that was already published
}
my_ping_index( $post_id );
}, 10, 3 );The gotcha
The name only encodes the new status, so publish_post also fires on every update of a post that is already published. Since WordPress 5.9 the third argument is $old_status, which lets you skip those, as in the example. For one exact change you can hook {$old_status}_to_{$new_status}, such as draft_to_publish, but a post published from the editor can arrive as auto-draft_to_publish as well.
Called in
wp-includes/post.php:5987 (WordPress 7.1.4)
Images & media 9
Sets the pixel limit above which WordPress makes a smaller "-scaled" copy of an upload and uses it as the full-size image. Default 2560. Return false to turn scaling off.
Fires
On upload, in wp_create_image_subsizes(), before the sub-sizes are made. On an HTTPS or localhost site, WordPress 7.1 also runs it when the block editor loads, for users who can upload files, with $imagesize array( 0, 0 ), an empty $file and $attachment_id 0, and images the browser resizes use that one value.
Signature
add_filter( 'big_image_size_threshold', 'my_callback', 10, 4 ); // receives $threshold, $imagesize, $file, $attachment_idExample
// Keep originals at full resolution (no -scaled copy).
add_filter( 'big_image_size_threshold', '__return_false' );
// Or raise the limit:
add_filter( 'big_image_size_threshold', function () {
return 3840;
} );The gotcha
It applies when either edge is over the limit, and only to images processed after the filter is active. The original stays on disk and core makes the sub-sizes from it, but the -scaled file becomes the attachment's full size. A test on 2026-11-06 (WordPress 7.1.4, PHP 8.3, GD, in WordPress Playground with Regenerate Thumbnails 3.1.6) showed the catch: after raising the limit to 3840, regenerating made a new 3840 px file, but after switching scaling off with __return_false, regenerating kept the 2560 px file as the full size. Only a fresh upload used the original. A fixed limit also reaches images the block editor resizes in the browser: in our test on 2026-11-16 (WordPress 7.1.4, Chromium 159, Playground on localhost), returning 3840 gave a 3840 px -scaled file from the browser and from the Media Library alike. A callback that decides per file cannot do that: the value the browser uses comes from the call with array( 0, 0 ), '' and 0, and core overrides the call that has the real file.
Called in
wp-admin/includes/image.php:285 (WordPress 7.1.4)
Filters the image sizes the server is about to make for an upload. Unset a size and the server does not make it.
Fires
On every upload of an image type WordPress makes sizes for (not TIFF, for example), in wp_create_image_subsizes(), before the server makes the sub-sizes (PDF previews use fallback_intermediate_image_sizes instead). When the block editor resizes an image in the browser, the filter still runs, but WordPress then replaces its result with an empty list (at priority 100), and the browser makes the sizes WordPress lists as missing, which this filter does not change.
Signature
add_filter( 'intermediate_image_sizes_advanced', 'my_callback', 10, 3 ); // receives $new_sizes, $image_meta, $attachment_idExample
add_filter( 'intermediate_image_sizes_advanced', function ( $sizes ) {
unset( $sizes['1536x1536'] );
unset( $sizes['2048x2048'] );
return $sizes;
} );The gotcha
If you remove a size the theme asks for by name, WordPress has no file for it and falls back to the full-size image, which the browser then shrinks. That costs visitors more bandwidth than the disk space it saves. The filter only affects images processed after it is added; files already on disk stay there. The bigger catch is WordPress 7.1: on an HTTPS or localhost site, the block editor resizes images in the browser in Chrome, Edge and other Chromium browsers from version 137, unless the device or connection makes the editor fall back to the server (2 GB of memory or less, one CPU core, Data Saver, a 2G connection, or a Content Security Policy that blocks blob: workers). Your callback still runs for those uploads but has no effect on them. In our test on 2026-11-16 (WordPress 7.1.4, Chromium 159, Playground on localhost), the example above stopped the 1536 and 2048 files for Media Library uploads, but a block-editor upload still got both. remove_image_size() and the intermediate_image_sizes filter stopped them on both paths. To stop a size everywhere, use the intermediate_image_sizes filter, which works for any size, or remove_image_size() for sizes added with add_image_size() (1536x1536, 2048x2048 and theme or plugin sizes); it does nothing for thumbnail, medium, medium_large or large. The 7.1.4 source also skips this filter when WordPress makes missing sizes later, for example after a failed upload.
Called in
wp-admin/includes/image.php:410 (WordPress 7.1.4)
Sets the JPEG quality WordPress uses when it writes resized JPEGs. Default 82.
Fires
When an image editor (GD or Imagick) sets its quality for a JPEG. $context is 'image_resize' when sizes are made on upload.
Signature
add_filter( 'jpeg_quality', 'my_callback', 10, 2 ); // receives $quality, $contextThe gotcha
For JPEGs it runs after wp_editor_set_quality and its value wins, so when both filters are set, this one decides. JPEG compression suits photos; screenshots and graphics with text show artefacts around sharp edges at settings where a photo still looks clean.
Called in
wp-includes/class-wp-image-editor.php:288 (WordPress 7.1.4)
Sets the output quality for every format the WP_Image_Editor classes (GD and Imagick) write. The defaults are 82, and 86 for WebP.
Fires
When an image editor sets its quality, before it saves a file.
Signature
add_filter( 'wp_editor_set_quality', 'my_callback', 10, 3 ); // receives $quality, $mime_type, $sizeThe gotcha
For JPEGs, jpeg_quality runs afterwards and overrides this value. The third argument, $size (the output width and height), was added in WordPress 6.8, so you can use a different quality for small thumbnails.
Called in
wp-includes/class-wp-image-editor.php:269 (WordPress 7.1.4)
Adds your custom image sizes to the size dropdown in the media modal and the block editor.
Fires
When the media UI builds its size selector.
Signature
add_filter( 'image_size_names_choose', 'my_callback' ); // receives $sizesExample
add_filter( 'image_size_names_choose', function ( $sizes ) {
return array_merge( $sizes, array( 'card' => __( 'Card', 'textdomain' ) ) );
} );The gotcha
add_image_size() registers a size but does not list it in the editor, so without this filter the size is made on upload and never offered in the dropdown. The default list holds only Thumbnail, Medium, Large and Full Size; medium_large, 1536x1536 and 2048x2048 are not in it either.
Called in
wp-admin/includes/media.php:1218 (WordPress 7.1.4)
Inspects or rejects a file before it is moved into the uploads folder.
Fires
In wp_handle_upload(), before the file is checked and moved. Media Library uploads and multipart REST API uploads take this path.
Signature
add_filter( 'wp_handle_upload_prefilter', 'my_callback' ); // receives $fileThe gotcha
To reject a file, set $file['error'] to a message and return $file; WordPress shows that message as the upload error. The hook name is built as {$action}_prefilter, so sideloaded files (media_handle_sideload(), and REST API uploads sent as a raw request body) fire wp_handle_sideload_prefilter instead. Hook both to catch every upload.
Called in
wp-admin/includes/file.php:840 (WordPress 7.1.4)
Filters an attachment's metadata array, including the list of generated sizes, after WordPress processes an upload.
Fires
After the server has made the sub-size files. $context is 'create' for a new upload and 'update' when missing sizes are made later. In WordPress 7.1, an image the block editor resizes in the browser runs it twice: 'create' with no sizes yet, then 'update' once the browser has sent them.
Signature
add_filter( 'wp_generate_attachment_metadata', 'my_callback', 10, 3 ); // receives $metadata, $attachment_id, $contextThe gotcha
Slow work here (a remote API call, extra image processing) adds to the time of every upload. Code that reads $metadata['sizes'] has to handle 'update' as well as 'create': in our test on 2026-11-16 (WordPress 7.1.4, Chromium 159, Playground on localhost), a block-editor upload ran it with 'create' and an empty sizes list, then with 'update' and all six sizes, while a Media Library upload ran it once, with 'create' and all six.
Called in
wp-admin/includes/image.php:750 (WordPress 7.1.4)
Filters the candidate files WordPress lists in an image's srcset.
Fires
When WordPress builds a responsive image, for wp_get_attachment_image() and for images in post content.
Signature
add_filter( 'wp_calculate_image_srcset', 'my_callback', 10, 5 ); // receives $sources, $size_array, $image_src, $image_meta, $attachment_idThe gotcha
$sources is keyed by width. Core only includes sizes with the same aspect ratio as the requested image and leaves out files wider than max_srcset_image_width (2048 px by default). If fewer than two candidates remain after this filter, WordPress prints no srcset at all, which is why a hard-cropped custom size with no other size of the same ratio gets none.
Called in
wp-includes/media.php:1632 (WordPress 7.1.4)
Filters the maximum upload size, in bytes, that WordPress shows and that its uploaders enforce. The default is the smaller of PHP's upload_max_filesize ($u_bytes) and post_max_size ($p_bytes).
Fires
Whenever wp_max_upload_size() runs: the Media Library uploader and its "Maximum upload file size" line, the block editor's settings, the REST API's upload-from-URL option, new in WordPress 7.1, and the importer's upload form under Tools > Import, which shows it as "Maximum size" (through the import_upload_size_limit filter).
Signature
add_filter( 'upload_size_limit', 'my_callback', 10, 3 ); // receives $size, $u_bytes, $p_bytesExample
add_filter( 'upload_size_limit', function ( $size ) {
return min( $size, 8 * MB_IN_BYTES ); // cap the WordPress uploaders at 8 MB
} );The gotcha
The uploaders check the size in the browser, before they send the file; on a single site the server does not check it again. In our test on 2026-11-16 (WordPress 7.1.4, Playground) with the limit set to 1 MB, the block editor and the Media Library both refused a 2.7 MB file, but the same file posted straight to the REST API was accepted. Upload-from-URL is the exception: there the server downloads the file itself and uses this value as its only limit, so raising it raises that limit too (read from the 7.1.4 source, not tested). For a normal upload it cannot raise the limit past PHP: a file larger than upload_max_filesize or post_max_size is refused by PHP before WordPress sees it, so to raise the limit you change those PHP settings. On multisite, core also hooks upload_size_limit_filter here to apply the network's maximum upload size, and checks that maximum on the server as well.
Called in
wp-includes/media.php:4340 (WordPress 7.1.4)
Admin 10
Prints a notice at the top of an admin screen.
Fires
While the admin screen renders, below its header.
Signature
add_action( 'admin_notices', 'my_callback' );The gotcha
It fires on every screen of a site's admin. Check get_current_screen() and show a notice only where it applies. On multisite, the network admin and the user dashboard fire network_admin_notices and user_admin_notices instead, and all_admin_notices fires on all three. The is-dismissible class adds a close button, but dismissing only hides the notice in that page view; to keep it gone, save the dismissal yourself.
Called in
wp-admin/admin-header.php:313 (WordPress 7.1.4)
Runs whenever a post is created or updated. The usual place to save meta box data.
Fires
In wp_insert_post(), after the post row is written to the database.
Signature
add_action( 'save_post', 'my_callback', 10, 3 ); // receives $post_id, $post, $updateExample
add_action( 'save_post', function ( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( wp_is_post_revision( $post_id ) ) return;
if ( ! current_user_can( 'edit_post', $post_id ) ) return;
// ... now it is safe to save
}, 10, 1 );The gotcha
It fires for autosaves and revisions as well as real saves. Without the three checks above, an autosave can overwrite your meta with empty values, which looks like data disappearing at random. In the block editor it can also run twice for one click: once for the REST API save, and again when the editor posts the classic meta boxes on the screen.
Called in
wp-includes/post.php:5286 (WordPress 7.1.4)
Registers meta boxes on the post edit screen.
Fires
When the post edit screen loads, in the classic editor and the block editor.
Signature
add_action( 'add_meta_boxes', 'my_callback', 10, 2 ); // receives $post_type, $postThe gotcha
Classic meta boxes do appear in the block editor, unless registered with '__back_compat_meta_box' => true. The editor saves them in a second request after the REST API save, so save_post runs twice. For new block-editor work, register the field with register_post_meta() and 'show_in_rest' => true instead.
Called in
wp-admin/includes/meta-boxes.php:1692 (WordPress 7.1.4)
Filters the row of action links under your plugin on the Plugins screen (Activate, Deactivate and so on). The usual way to add a "Settings" link.
Fires
While the Plugins list table renders each row.
Signature
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'my_callback' ); // receives $actions (also $plugin_file, $plugin_data, $context)Example
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), function ( $actions ) {
array_unshift( $actions, sprintf(
'<a href="%s">%s</a>',
esc_url( admin_url( 'options-general.php?page=my-plugin' ) ),
esc_html__( 'Settings', 'textdomain' )
) );
return $actions;
} );The gotcha
The dynamic part must be plugin_basename() of your main plugin file, such as my-plugin/my-plugin.php. Register this from an included file and __FILE__ points to that file, the hook name never matches, and the link never appears, with no error. array_unshift() puts Settings first; a plain append puts it after Deactivate.
Called in
wp-admin/includes/class-wp-plugins-list-table.php:1162 (WordPress 7.1.4)
Filters the column headers of the post list table for one post type. Keys are column slugs, values are the header labels.
Fires
When the list table builds its columns, before any row renders.
Signature
add_filter( 'manage_book_posts_columns', 'my_callback' ); // receives $columnsExample
add_filter( 'manage_book_posts_columns', function ( $columns ) {
$date = $columns['date'];
unset( $columns['date'] );
$columns['isbn'] = __( 'ISBN', 'textdomain' );
$columns['date'] = $date; // put Date back on the end
return $columns;
} );The gotcha
This only adds the header. The cells stay empty until you also hook manage_{$post_type}_posts_custom_column. A plain append puts your column after Date; unset Date and add it back as above. Core also fires manage_pages_columns for pages and manage_posts_columns (with the post type as a second argument) for every other type.
Called in
wp-admin/includes/class-wp-posts-list-table.php:755 (WordPress 7.1.4)
Prints the cell contents for a custom column you added to the post list table. You echo; you do not return.
Fires
Once per custom column per row, while the list table renders.
Signature
add_action( 'manage_book_posts_custom_column', 'my_callback', 10, 2 ); // receives $column, $post_idExample
add_action( 'manage_book_posts_custom_column', function ( $column, $post_id ) {
if ( 'isbn' === $column ) {
echo esc_html( get_post_meta( $post_id, 'isbn', true ) );
}
}, 10, 2 );The gotcha
This one is an action that echoes, like the comments, media and plugins list tables. The users and taxonomy-term tables are the exceptions: there the hooks are filters that return a value, with a different argument order. manage_users_custom_column receives ( $output, $column_name, $user_id ) and manage_{$taxonomy}_custom_column receives ( $output, $column_name, $term_id ). Copy the post version to the users screen and the column stays empty, with no warning.
Called in
wp-admin/includes/class-wp-posts-list-table.php:1508 (WordPress 7.1.4)
Adds classes to the admin <body>, so you can scope admin CSS to one screen.
Fires
When the admin header prints the opening body tag.
Signature
add_filter( 'admin_body_class', 'my_callback' ); // receives $classesExample
add_filter( 'admin_body_class', function ( $classes ) {
$screen = get_current_screen();
if ( $screen && 'book' === $screen->post_type ) {
$classes .= ' my-book-screen'; // note the leading space
}
return $classes;
} );The gotcha
It passes a space-separated string, unlike the front-end body_class filter, which passes an array, and the first callback gets an empty string. Code written for body_class ($classes[] = 'x') stops wp-admin with a fatal error, "[] operator not supported for strings". Add each class with a leading space, as in the example: without it, your class fuses onto one an earlier callback added and the selector never matches.
Called in
wp-admin/admin-header.php:252 (WordPress 7.1.4)
Handles a form POST or link sent to admin-post.php by a logged-in user. The supported alternative to writing your own endpoint file.
Fires
On a request to wp-admin/admin-post.php whose action parameter matches the suffix.
Signature
add_action( 'admin_post_my_action', 'my_callback' ); // no argumentsExample
add_action( 'admin_post_my_action', function () {
check_admin_referer( 'my_action' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'Nope.', 'textdomain' ), 403 );
}
update_option( 'my_thing', sanitize_text_field( wp_unslash( $_POST['my_thing'] ?? '' ) ) );
wp_safe_redirect( add_query_arg( 'updated', '1', admin_url( 'options-general.php?page=my-plugin' ) ) );
exit; // stop here: admin-post.php ends right after this hook, and any code after the redirect would still run
} );The gotcha
Logged-out requests fire admin_post_nopriv_{$action} instead, so a public form that works while you test it logged in fails for visitors. admin-post.php prints nothing for you: finish with wp_safe_redirect() and exit, or the user sees a blank page. It also runs no nonce or capability check; those are yours to write.
Called in
wp-admin/admin-post.php:82 (WordPress 7.1.4)
Users & auth 3
Runs after a user logs in successfully.
Fires
In wp_signon(), after the credentials pass and the login cookie is set.
Signature
add_action( 'wp_login', 'my_callback', 10, 2 ); // receives $user_login, WP_User $userCalled in
wp-includes/user.php:138 (WordPress 7.1.4)
Runs right after wp_insert_user() creates a new user.
Fires
When a new user is created, whether by registration, the admin or code.
Signature
add_action( 'user_register', 'my_callback', 10, 2 ); // receives $user_id, $userdataCalled in
wp-includes/user.php:2711 (WordPress 7.1.4)
Filters the result of a login attempt. Return a WP_User to allow it or a WP_Error to refuse it.
Fires
In wp_authenticate(), on every login attempt.
Signature
add_filter( 'authenticate', 'my_callback', 30, 3 ); // receives $user, $username, $passwordThe gotcha
Core hooks its own checks at priority 20 (username or email plus password, and application passwords), 30 (the login cookie, added by wp_signon()) and 99 (the multisite spam check). When both fields are filled in, the priority 20 password check ignores a WP_Error returned before it and replaces it with its own result, so a block added at priority 10 does nothing. Hook later than 20, and pass on any WP_Error you receive.
Called in
wp-includes/pluggable.php:706 (WordPress 7.1.4)
REST, AJAX & cron 8
Registers REST API routes and fields.
Fires
When the REST API server starts up for a request.
Signature
add_action( 'rest_api_init', 'my_callback' );Example
add_action( 'rest_api_init', function () {
register_rest_route( 'myplugin/v1', '/items', array(
'methods' => 'GET',
'callback' => 'my_get_items',
'permission_callback' => '__return_true', // be deliberate about this
) );
} );The gotcha
Since WordPress 5.5, a route registered without permission_callback triggers a _doing_it_wrong notice. Setting it to __return_true makes the endpoint fully public, which suits public data and is a security hole for anything else. Choose it per route.
Called in
wp-includes/rest-api.php:657 (WordPress 7.1.4)
Decides whether a REST API request may continue. Return a WP_Error to refuse it, or pass the value through unchanged.
Fires
In WP_REST_Server::serve_request(), before the request is dispatched to a route and before any route's permission_callback.
Signature
add_filter( 'rest_authentication_errors', 'my_callback' ); // receives WP_Error|null|true $errorsExample
add_filter( 'rest_authentication_errors', function ( $errors ) {
if ( ! empty( $errors ) ) {
return $errors; // another check already decided
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'rest_forbidden', 'Login required.', array( 'status' => 401 ) );
}
return $errors;
} );The gotcha
Return early if $errors is already set, or you overrule whatever ran before you, such as another authentication plugin. Never return a bare true: core's cookie check (rest_cookie_check_errors, priority 100) skips its nonce check when it receives a non-empty value, so returning true from an earlier priority switches off the cross-site request protection for logged-in users.
Called in
wp-includes/rest-api/class-wp-rest-server.php:197 (WordPress 7.1.4)
Lets you answer a REST API request before it is routed. Return anything other than null and that becomes the response.
Fires
At the start of WP_REST_Server::dispatch(), after authentication and before the route is matched, its permission_callback runs or its callback runs.
Signature
add_filter( 'rest_pre_dispatch', 'my_callback', 10, 3 ); // receives $result, WP_REST_Server $server, WP_REST_Request $requestExample
add_filter( 'rest_pre_dispatch', function ( $result, $server, $request ) {
if ( '/myplugin/v1/report' !== $request->get_route() ) {
return $result; // null = carry on normally
}
$cached = get_transient( 'my_report' );
return ( false === $cached ) ? $result : rest_ensure_response( $cached );
}, 10, 3 );The gotcha
Returning a value skips the endpoint completely, permission_callback included. Serve a cached response here and you serve it to everyone, logged in or not, so do your own capability check first. Return $result (usually null) in every other case; a callback that always returns something replaces every REST API response on the site, the block editor's included.
Called in
wp-includes/rest-api/class-wp-rest-server.php:1079 (WordPress 7.1.4)
Filters the REST API response for one post of that post type, just before it is returned. Use it to add, reshape or remove fields.
Fires
Once per item, after the item is prepared, for single-item and collection requests alike.
Signature
add_filter( 'rest_prepare_post', 'my_callback', 10, 3 ); // receives WP_REST_Response $response, WP_Post $post, WP_REST_Request $requestExample
add_filter( 'rest_prepare_post', function ( $response, $post, $request ) {
$response->data['reading_time'] = (int) ceil( str_word_count( wp_strip_all_tags( $post->post_content ) ) / 200 );
return $response;
}, 10, 3 );The gotcha
$response is a WP_REST_Response object, not an array: change $response->data and return the object. A field added here appears in the output (and ?_fields= can select it, because core filters the final data), but it is not in the endpoint's schema and clients cannot write to it. If they need to, use register_rest_field() on rest_api_init. The hook name uses the post type slug: rest_prepare_page, rest_prepare_attachment, rest_prepare_book.
Called in
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:2199 (WordPress 7.1.4)
Filters the WP_Query arguments a REST API collection request is about to run, so you can support query parameters core does not map.
Fires
When a posts collection endpoint (GET /wp/v2/posts, /wp/v2/pages, a custom post type) builds its query, before the query runs.
Signature
add_filter( 'rest_post_query', 'my_callback', 10, 2 ); // receives array $args, WP_REST_Request $requestExample
add_filter( 'rest_post_query', function ( $args, $request ) {
if ( $request->get_param( 'featured' ) ) {
$args['meta_key'] = 'is_featured';
$args['meta_value'] = '1';
}
return $args;
}, 10, 2 );The gotcha
$request->get_param() returns any parameter sent with the request, registered or not. Core only turns registered collection parameters into WP_Query arguments, which is why you map your own here. Register it with the rest_{$post_type}_collection_params filter as well, so it is validated and listed in the schema. pre_get_posts also fires for these queries, so a front-end pre_get_posts callback without an is_main_query() check changes API results too.
Called in
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:444 (WordPress 7.1.4)
Handles an admin-ajax.php request from a logged-in user. The hook name is built from the 'action' value your JavaScript sends.
Fires
In admin-ajax.php, after WordPress loads and the current user is set, for logged-in users only.
Signature
add_action( 'wp_ajax_my_action', 'my_callback' ); // $action = the 'action' param sent in the requestExample
add_action( 'wp_ajax_my_save_thing', function () {
check_ajax_referer( 'my_save_thing' ); // nonce, or anyone can call this
if ( ! current_user_can( 'edit_posts' ) ) {
wp_send_json_error( 'nope', 403 ); // logged in is not the same as allowed
}
update_option( 'my_thing', sanitize_text_field( wp_unslash( $_POST['value'] ?? '' ) ) );
wp_send_json_success( array( 'saved' => true ) ); // ends the request for you
} );The gotcha
Your handler must end the request. If it just returns, admin-ajax.php calls wp_die( '0' ), a stray 0 follows your output, and the JSON fails to parse. wp_send_json_success() and wp_send_json_error() end the request for you; a plain echo does not. Being logged in is not permission: any subscriber account can call this action, so check a nonce with check_ajax_referer() and a capability with current_user_can().
Called in
wp-admin/admin-ajax.php:192 (WordPress 7.1.4)
Handles an admin-ajax.php request from a logged-out visitor. Same action name, separate hook.
Fires
In admin-ajax.php, for visitors who are not logged in.
Signature
add_action( 'wp_ajax_nopriv_my_action', 'my_callback' );Example
// Front-end AJAX has to be registered TWICE to work for everyone.
add_action( 'wp_ajax_my_public_thing', 'my_handler' );
add_action( 'wp_ajax_nopriv_my_public_thing', 'my_handler' );The gotcha
If no nopriv handler is registered, admin-ajax.php answers logged-out visitors with 0 and HTTP 400. That is the usual cause of AJAX that works while you are logged in and fails after you log out. Front-end AJAX needs both hooks. Logged-out visitors all receive the same nonce, so a nonce here only shows that the request came from your page, not who sent it; never put anything behind this hook that a stranger should not run.
Called in
wp-admin/admin-ajax.php:207 (WordPress 7.1.4)
Adds a custom recurrence interval for wp_schedule_event().
Fires
When WordPress builds its list of available schedules.
Signature
add_filter( 'cron_schedules', 'my_callback' ); // receives $schedulesExample
add_filter( 'cron_schedules', function ( $schedules ) {
$schedules['every_five_minutes'] = array(
'interval' => 300, // seconds
'display' => __( 'Every 5 minutes', 'textdomain' ),
);
return $schedules;
} );The gotcha
WP-Cron is not a system cron. It only runs when someone loads a page, so on a quiet site a five-minute schedule runs late. If the timing matters, set DISABLE_WP_CRON and call wp-cron.php from a real system cron.
Called in
wp-includes/cron.php:1169 (WordPress 7.1.4)
Comments 2
Runs right after a new comment is saved.
Fires
At the end of wp_new_comment(), which handles comment form submissions.
Signature
add_action( 'comment_post', 'my_callback', 10, 3 ); // receives $comment_id, $approved, $commentdataCalled in
wp-includes/comment.php:2491 (WordPress 7.1.4)
Filters comment data before it is saved. Used for spam checks and validation.
Fires
At the start of wp_new_comment(), before the comment is checked and written.
Signature
add_filter( 'preprocess_comment', 'my_callback' ); // receives $commentdataThe gotcha
Returning false does not stop the comment; WordPress carries on with broken data. To refuse a comment with a message, call wp_die() here, or return a WP_Error from the pre_comment_approved filter, which WordPress has accepted for this since 4.9.0.
Called in
wp-includes/comment.php:2405 (WordPress 7.1.4)
WooCommerce 3
Runs on the order-received (thank you) page. WooCommerce prints its own order details table on this hook at priority 10.
Fires
Each time the order-received page loads, in the classic template and in the Order Confirmation block.
Signature
add_action( 'woocommerce_thankyou', 'my_callback' ); // receives $order_idThe gotcha
Do not use it to start fulfilment. It only runs if the customer reaches the page, it runs again on every reload, and the template fires it for failed orders too. Use woocommerce_payment_complete (fired when a payment gateway calls $order->payment_complete()) or an order status hook such as woocommerce_order_status_processing.
Called in
templates/checkout/thankyou.php:97 (WooCommerce 11.2.2)
Adds, removes or reorders fields on the classic checkout.
Fires
When WooCommerce first builds the checkout field list for a request.
Signature
add_filter( 'woocommerce_checkout_fields', 'my_callback' ); // receives $fieldsThe gotcha
It only affects the classic, shortcode-based checkout. The Checkout block does not read this filter. For the block checkout, WooCommerce provides woocommerce_register_additional_checkout_field(), a PHP function for adding fields.
Called in
includes/class-wc-checkout.php:322 (WooCommerce 11.2.2)
Put these hooks to work
- The disable scaled images generator writes a ready-made big_image_size_threshold filter.
- The WordPress JPEG quality generator writes a jpeg_quality filter for every JPEG size, or a wp_editor_set_quality filter if you choose higher quality for large files only.
- If an upload still looks soft after you change those filters, the guide to blurry images after upload walks through the -scaled copy and the regenerate trap.
- The WordPress image sizes cheat sheet lists the core and WooCommerce default sizes that intermediate_image_sizes_advanced receives, with their dimensions and crop. Sizes your theme and plugins register arrive in the same array.
- The child theme troubleshooting guide covers the stylesheet order behind the wp_enqueue_scripts example.
- upload_size_limit cannot raise the limit for normal uploads past PHP's own settings (upload-from-URL is the one exception, see its entry); raising the WordPress upload limit means changing those PHP settings.
- Several entries mention _doing_it_wrong notices. The WordPress debug mode guide shows how to log them while you test a callback.
- The whole index is also published as open data in JSON, under CC BY 4.0.
Sources
Every signature, argument count and "Called in" line was read from the release packages below on 2026-11-16. The examples were checked against the same source. Most were not run on a site; where an entry says "in our test", that behaviour was run in WordPress Playground on the date given. Each "Called in" line links to that file and line at the 7.1.4 tag of the WordPress mirror on GitHub, or the 11.2.2 tag of the WooCommerce repository.
- WordPress 7.1.4 release package, a zip download (wordpress.org)
- WordPress 7.1.4 source, browsable on GitHub (github.com/WordPress)
- WooCommerce 11.2.2 plugin package, a zip download (downloads.wordpress.org)
- WooCommerce 11.2.2 plugin source on GitHub (github.com/woocommerce)
- WordPress Code Reference: Hooks (developer.wordpress.org)
- Plugin Handbook: Hooks (developer.wordpress.org)