首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加载特定分类的特定函数文件

问加载特定分类的特定函数文件
EN

WordPress Development用户
提问于 2021-05-16 13:11:03
回答 1查看 54关注 0票数 0

我已经将我的所有函数分割成不同的文件,并使用以下方法从functions.php加载这些文件:

代码语言:javascript
复制
require get_template_directory() . '/inc/bhh-functions/scripts-styles.php';
require get_template_directory() . '/inc/bhh-functions/user-functions.php';

但是,我现在有一个函数文件,我只想加载到某个分类法页面上。我已经尝试了以下和其他可能性,但没有运气。

代码语言:javascript
复制
if (has_term('16', 'product_cat', )) {
  require get_template_directory() . '/inc/bhh-functions/tax-functions.php';
}
EN

回答 1

WordPress Development用户

发布于 2021-05-17 09:20:36

代码语言:javascript
复制
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';
    }
}
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/388255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档