我正在創建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
偉大的,它的工作,謝謝。 –