php - Override a Wordpress parent theme function -
i creating child theme of flowmaster theme.i have problem override parent function. 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 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 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 executed first , parent theme's. checking using function_exists
should have been done in parent theme.
to overcome can remove parent theme's hook , hook custom function same filter.
remove_filter('loop_shop_columns', 'pt_loop_shop_columns'); add_filter('loop_shop_columns', 'custom_pt_loop_shop_columns'); function custom_pt_loop_shop_columns(){ global $wp_query; if ( 'layout-one-col' == pt_show_layout() ) return 4; else return 4; }
Comments
Post a Comment