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' );
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' );
Share
Improve this question
asked Jun 29, 2019 at 8:22
wpdevwpdev
5492 gold badges13 silver badges28 bronze badges
0
2 Answers
Reset to default 2Neither. 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.
Try with outside if
function overridable_function() {
echo 'Test';
}
add_action( 'init', 'overridable_function' );