Performance: Removing hooks
This affects how quickly WordPress processes actions and filters during page load and interaction.
<?php remove_action('wp_head', 'heavy_function'); ?>
<?php function heavy_function() { /* heavy processing */ } add_action('wp_head', 'heavy_function'); ?>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Keeping heavy hooks active | No direct DOM changes | 0 | 0 | [X] Bad |
| Removing heavy hooks | No direct DOM changes | 0 | 0 | [OK] Good |
remove_action or remove_filter in WordPress?remove_action or remove_filter stops those custom functions from running.my_custom_action with a callback function my_function?remove_action function requires the hook name as a string and the callback function name as a string.function greet() {
echo 'Hello!';
}
add_action('wp_footer', 'greet');
remove_action('wp_footer', 'greet');greet is added to run on the wp_footer hook, so it would print 'Hello!'.remove_action stops greet from running on wp_footer.modify_title with callback change_title?
add_filter('the_title', 'change_title', 5);
remove_filter('the_title', 'change_title', 10);add_filter call uses priority 5.remove_filter specifies priority 10, which does not match.remove_filter call does not work. The plugin adds the filter like this:add_filter('content_filter', ['PluginClass', 'modify_content'], 15);functions.php?['PluginClass', 'modify_content'] with priority 15.['PluginClass', 'modify_content'] matches exactly; no object instance needed for class callbacks.Pass the test and this pattern moves unknown