0

Where i must put hooks in overridable functions for better child themes? Inside if statement or outside?

if( !function_exists( ovveridable_function() ) {
    function overridable_function() {
        echo 'Test';
    }
    add_action( 'init', 'overridable_function' );
}

OR

if( !function_exists( ovveridable_function() ) {
    function overridable_function() {
        echo 'Test';
    }
}
add_action( 'init', 'overridable_function' );
2

Neither. Hooked functions don’t need to be pluggable because child themes can already unhook and replace them with remove_action().

The main functions that you’d want to make pluggable are functions that are used in templates i.e. template tags, and those functions aren’t usually hooked, so the placement of add_action() isn’t relevant. Even then you probably only need to make them pluggable if they’re used in multiple templates, because otherwise the child theme could just replace the template file.

-2

Try with outside if

function overridable_function() {
    echo 'Test';
}
add_action( 'init', 'overridable_function' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.