我已经将我的所有函数分割成不同的文件,并使用以下方法从functions.php加载这些文件:
require get_template_directory() . '/inc/bhh-functions/scripts-styles.php';
require get_template_directory() . '/inc/bhh-functions/user-functions.php';但是,我现在有一个函数文件,我只想加载到某个分类法页面上。我已经尝试了以下和其他可能性,但没有运气。
if (has_term('16', 'product_cat', )) {
require get_template_directory() . '/inc/bhh-functions/tax-functions.php';
}发布于 2021-05-17 09:20:36
add_action('template_redirect', 'bhh_single_product_functions', 10);
function bhh_single_product_functions()
{
if (has_term(16, 'product_cat',)) {
require get_template_directory() . '/inc/bhh-functions/single-product-category-x.php';
}
}https://wordpress.stackexchange.com/questions/388255
复制相似问题