我正在创建flowmaster theme的子主题。我有一个问题来覆盖父函数。 功能在父母的主题存在:覆盖Wordpress的父主题功能
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;
}
我在儿童主题
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');
得到这个错误添加函数:
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
请help.Thanks
谢谢,为您的reply.function_exists未添加到父主题中。将此代码添加到子主题函数中,错误已消失。但其未在行中返回4个项目,其中仍有3个项目在行中。 –
然后尝试降低优先级,'add_filter('loop_shop_columns','custom_pt_loop_shop_columns',20);' – Nilambar
伟大的,它的工作,谢谢。 –