【问题标题】:Show content if the post belongs to a specific author如果帖子属于特定作者,则显示内容
【发布时间】:2021-02-22 02:09:18
【问题描述】:

如果访问者访问的帖子属于特定作者,我想知道是否有任何方法可以为访问者启用脚本。

这是我想包含在 header.php 或 single.php 中的脚本,如果访问者转到属于 James 的帖子,请在标题中显示或启用以下脚本:

<script src="/wpauthors/james.js"></script>

【问题讨论】:

    标签: wordpress author


    【解决方案1】:
    function authScript() {
        if(get_the_author_meta('ID' == 2) {  // 2 is James uer ID here
          echo '<script src="/wpauthors/james.js"></script>';
        }
    }
    add_action('wp_head', 'authScript');
    

    将此添加到您的functions.php。它应该工作。自己没有测试过。

    【讨论】:

      猜你喜欢
      • 2011-11-13
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多