admin管理员组文章数量:1391955
I'm trying to noindex posts from all authors EXCEPT 3 authors on my Wordpress site.
I found the following code that I can put into the header.php file. However, this targets specific categories.
<?php if (is_single() && (in_category(array(457)))) {
echo '<meta name="robots" content="noindex, follow">';
} ?>
How do I modify this to say something like, if is single post and is NOT an author with ID 111, 112, or 113 then insert noindex, follow. Would the following be correct?:
<?php if (is_single() && !(is_author(array(111,112,113)))) {
echo '<meta name="robots" content="noindex, follow">';
} ?>
I'm trying to noindex posts from all authors EXCEPT 3 authors on my Wordpress site.
I found the following code that I can put into the header.php file. However, this targets specific categories.
<?php if (is_single() && (in_category(array(457)))) {
echo '<meta name="robots" content="noindex, follow">';
} ?>
How do I modify this to say something like, if is single post and is NOT an author with ID 111, 112, or 113 then insert noindex, follow. Would the following be correct?:
<?php if (is_single() && !(is_author(array(111,112,113)))) {
echo '<meta name="robots" content="noindex, follow">';
} ?>
Share
Improve this question
asked Feb 19, 2020 at 18:44
TnaceTnace
173 bronze badges
1 Answer
Reset to default 1From codex: is_author() is a conditional tag which determines whether the query is for an existing author archive page. so it does not work for your scope.
Best solution, instead of using the template file header.php is to write a function in functions.php hooking the proper action wp_head
:
add_action('wp_head','AS_exclude_author_from_indexing');
function AS_exclude_author_from_indexing(){
$toIndex = array(111,112,113);
$user_id = get_the_author_meta( 'ID' );
if( !in_array($user_id,$toIndex)){
echo "<meta name=\"robots\" content=\"noindex,follow\">".PHP_EOL;
}
}
本文标签: phpNoindex Posts From Certain Authors In Wordpress
版权声明:本文标题:php - Noindex Posts From Certain Authors In Wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744732336a2622122.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论