Hi @bigmoxy ,
You can override an entire function if the function in the parent functions.php file is conditionally defined like this:
if ( ! function_exists( 'some_function' ) ) {
function some_function() {
}
}
You can then define the function with the same name inside the child theme’s functions.php because child theme will execute before parent theme.
Or, you can override an entire function defined in parent theme if it is assigned as a callback to a hook.
For example, in your parent functions.php, you have a callback function:
add_filter( 'the_content', 'append_thank_you' );
function append_thank_you( $content ) {
return $content . '-- thank you!';
}
You remove this filter hook in the child theme functions.php as:
add_action( 'init', function() {
remove_filter( 'the_content', 'append_thank_you' );
} );
and implement your own custom callback function for the the_content
hook.
You can modify the behaviour of a function in the parent theme if the function itself provides action or filter hooks.
For example, the function you want to “override” is something like this:
function some_function() {
$title = 'Hello World!';
do_action( 'some_function_action_hook', $title );
return apply_filters( 'some_function_filter_hook', $title );
}
Then, you can utilise some_function_action_hook
action hook and some_function_filter_hook
filter hook to modify the behaviour of the function.
—-
The purpose of a child theme is to customise parent theme’s features without directly modifying the parent theme’s files.