如果文章属于特定作者,则显示内容



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

这是一个脚本,我想包括在header.php或在single.php,如果访问者去一个帖子,属于詹姆斯,显示或启用以下脚本在头:

<script src="/wpauthors/james.js"></script>
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中。这应该行得通。我自己没有测试过。

最新更新