I am creating a child theme of flowmaster theme.I have a problem to override the parent function.
The function exists in parent’s theme:
add_filter('loop_shop_columns', 'pt_loop_shop_columns');
function pt_loop_shop_columns(){
if ( 'layout-one-col' == pt_show_layout() ) return 4;
else return 3;
}
I add a function in child theme
if ( ! function_exists( 'pt_loop_shop_columns' ) ) :
function pt_loop_shop_columns(){
global $wp_query;
if ( 'layout-one-col' == pt_show_layout() ) return 4;
else return 4;
}
endif;
add_filter('loop_shop_columns', 'pt_loop_shop_columns');
Got this error:
Fatal error: Cannot redeclare pt_loop_shop_columns() (previously
declared in
C:\xampp\htdocs\futuratab\wp-content\themes\flowmaster-child\functions.php:44)
in
C:\xampp\htdocs\futuratab\wp-content\themes\flowmaster\woofunctions.php
on line 9
Please help.Thanks
Function of child theme is executed first and then parent theme’s. Checking using
function_exists
should have been done in parent theme.To overcome this you can remove parent theme’s hook and hook your custom function to same filter.
You can’t redefine a function in PHP, but you can unhook the old function and hook the new one with a different name. Something like:
you can try this on your child theme
OR
you can use hook on existing function
OR
And last method is