Removing parent theme action on pluggable function not working

The parent theme’s functions.php runs after the child theme’s, so in order to remove an action defined by the parent theme the remove_action call must be delayed using a hook after the parent theme registers the action. So putting the remove_action call purely inside the child’s functions.php won’t work. It must be attached to a hook.

However from the code excerpt in the question it is not clear if the parent’s add_action( 'tha_content_while_before', 'fwp_archive_header' ); line is just in functions.php or is that inside an action? If it is inside an action, hook the remove_action call to the same action but with bigger priority (so it runs after). Note I’m talking about the action the parent add_action call is inside. Something like this:

add_action( 'some_hook', 'some_parent_function', 10 );
function some_parent_function() {
    /* ...some code... */
    add_action( 'tha_content_while_before', 'fwp_archive_header' );
    if ( !function_exists('fwp_archive_header') ) {
        function fwp_archive_header() {
          // do stuff
        }
    }
    /* ...some code... */
}

The remove would look like:

add_action( 'some_hook', 'remove_parent_actions_filters', 11 );
function remove_parent_actions_filters() { 
  remove_action( 'tha_content_while_before', 'fwp_archive_header' );
}

Another rule of thumb attempt is to hook your remove call to wp_loaded, e.g.: add_action( 'wp_loaded', 'remove_parent_actions_filters', 1000 );. Should be still on time to affect how pages are rendered, but would likely be late enough to override most common parent theme hooks.


On the other hand declaring an empty function with the name fwp_archive_header is almost as good solution. Note though it is not “redeclare”, as there’s no such thing in PHP. It’s more like “predeclare”, before the parent theme, so the parent theme won’t declare it’s own function with the same name (with appropriate checks in place).