remove_action( string $hook_name, callable|string|array $callback, int $priority = 10 ): bool
- Since
- 1.2.0
- Source
wp-includes/plugin.php:622
Detaches a specific callback from an action hook by hook name, callback, and priority, the same three values used when the callback was originally attached. It works by calling remove_filter() under the hood, since WordPress stores actions and filters in the same hook structure. The priority must match exactly or the removal silently fails with no warning, which is the most common source of confusion when using it.
Description
This can be used to remove default functions attached to a specific action hook and possibly replace them with a substitute.
To remove a hook, the $callback and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.
Compatibility
- WordPress
- since 1.2.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$hook_namestring- The action hook to which the function to be removed is hooked.
$callbackcallable|string|array- The name of the function which should be removed.
This function can be called unconditionally to speculatively remove a callback that may or may not exist. $priorityintoptional- The exact priority used when adding the original action callback. Default 10.Default:
10
Return value
bool- Whether the function is removed.
Code examples
Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.
Remove a default WordPress head action like feed links
WordPress attaches the core feed_links() function to wp_head at priority 2 by default, so remove it and confirm the output no longer includes the feed link markup.
remove_action( 'wp_head', 'feed_links', 2 );
ob_start();
do_action( 'wp_head' );
$head_output = ob_get_clean();
if ( false === strpos( $head_output, 'alternate' ) ) {
echo esc_html( 'feed_links output was successfully removed from wp_head.' );
} else {
echo esc_html( 'feed_links still ran, removal did not match.' );
}The priority argument (2) has to match the priority WordPress used when it originally hooked feed_links onto wp_head, otherwise nothing is removed.
Check whether remove_action actually found and removed a callback
Attach a custom callback at priority 20 on a fictional hook, then try removing it with the wrong priority before the right one to see how the return value behaves.
function acme_log_price_change() {
echo esc_html( 'Price change logged.' );
}
add_action( 'acme_price_updated', 'acme_log_price_change', 20 );
$removed_with_wrong_priority = remove_action( 'acme_price_updated', 'acme_log_price_change', 10 );
$removed_with_right_priority = remove_action( 'acme_price_updated', 'acme_log_price_change', 20 );
printf(
'Wrong priority removal returned: %s. Right priority removal returned: %s.',
esc_html( $removed_with_wrong_priority ? 'true' : 'false' ),
esc_html( $removed_with_right_priority ? 'true' : 'false' )
);Common problems and fixes · 3
- Why doesn't remove_action() remove the callback I'm targeting?
- Why does my remove_action() call have no effect even though I'm sure the callback matches?
- How do I remove an action that was added as a class method?
Why doesn't remove_action() remove the callback I'm targeting?
Why does my remove_action() call have no effect even though I'm sure the callback matches?
How do I remove an action that was added as a class method?
Alternatives and related functions
add_action- When you want to attach a new callback instead of detaching an existing one, including re-adding a replacement after removing the default.
remove_filter- When the underlying function you actually want to call directly is being documented or debugged, since remove_action() is just a wrapper around it.
remove_all_actions- When you need to strip every callback from a hook regardless of priority, rather than removing one specific callback.
has_action- When you need to check whether a callback is currently attached to a hook before deciding whether to remove it.
Performance profile
How much work a call to remove_action() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 9
- Plugin surface
- None
- Called by
- 33
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 9.
Nothing here hands control to plugin code.
33 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost remove_action() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9 | remove_filter() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 9 instructions, 9 executed per call, 0 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- remove_filter()Removes a callback function from a filter hook.
Used by · 33
- Language_Pack_Upgrader::bulk_upgrade()Upgrades several language packs at once.
- Plugin_Upgrader::install()Install a plugin package.
- Plugin_Upgrader::upgrade()Upgrades a plugin.
- Theme_Upgrader::install()Install a theme package.
- Theme_Upgrader::upgrade()Upgrades a theme.
- WP_Automatic_Updater::run()Kicks off the background update process, looping through all pending updates.
- WP_Customize_Manager::__construct()Constructor.
- WP_MS_Themes_List_Table::single_row()Handles the output for a single table row.
- WP_Post_Type::remove_hooks()Removes the future post hook action for the post type.
- WP_Post_Type::unregister_meta_boxes()Unregisters the post type meta box if a custom callback was specified.
- WP_Roles::get_roles_data()Gets the available roles data.
- _remove_theme_support()Do not use. Removes theme support internally without knowledge of those not used by themes directly.
Show all 33
- _wp_customize_publish_changeset()Publishes a snapshot's changes.
- _wp_delete_customize_changeset_dependent_auto_drafts()Deletes auto-draft posts associated with the supplied changeset.
- _wp_get_iframed_editor_assets()Collect the block editor assets that need to be loaded into the editor's iframe.
- add_feed()Adds a new feed type like /atom1/.
- automatic_feed_links()Enable/disable automatic general feed link outputting.
- check_theme_switched()Checks if a theme has been changed and runs 'after_switch_theme' hook on the next WP load.
- locate_block_template()Finds a block template with equal or higher specificity than a given PHP template file.
- wp_enqueue_admin_bar_bump_styles()Enqueues inline bump styles to make room for the admin bar.
- wp_enqueue_admin_bar_header_styles()Enqueues inline style to hide the admin bar when printing.
- wp_enqueue_block_template_skip_link()Enqueues the skip-link styles.
- wp_enqueue_embed_styles()Enqueues the CSS in the embed iframe header.
- wp_enqueue_emoji_styles()Enqueues the important emoji-related styles.
- wp_enqueue_global_styles()Enqueues the global styles defined via theme.json.
- wp_enqueue_global_styles_custom_css()Enqueues the global styles custom css defined via theme.json.
- wp_enqueue_img_auto_sizes_contain_css_fix()Enqueues a CSS rule to fix potential visual issues with images using `sizes=auto`.
- wp_font_library_render_page()Render the font-library page.
- wp_hoist_late_printed_styles()Adds the hooks needed for CSS output to be delayed until after the content of the page has been established.
- wp_is_site_initialized()Checks whether a site is initialized.
- wp_oembed_add_discovery_links()Adds oEmbed discovery links in the head element of the website.
- wp_options_connectors_render_page()Render the options-connectors page.
- wp_print_media_templates()Prints the templates used in the media manager.
Source code
function remove_action( $hook_name, $callback, $priority = 10 ) { return remove_filter( $hook_name, $callback, $priority );}Changelog
Introduced in 1.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/plugin.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.