简体   繁体   English

仅当帖子作者是管理员时才从所有帖子中删除作者姓名(wordpress)

[英]Removing author name from all posts only if post author is admin (wordpress)

I can't seem to find the function code that will work for this to actually completely remove the author from posts only if the author is an admin.我似乎找不到 function 代码,只有在作者是管理员的情况下,才能真正从帖子中完全删除作者。 I have generic posts which will be published by admin but I do not want to have the admins name appear as an author (need it to be completely removed) Is there a way to do this without hiding it but rather completely remove it?我有将由管理员发布的通用帖子,但我不希望管理员名称显示为作者(需要将其完全删除)有没有办法做到这一点而不隐藏它,而是完全删除它?

Worse case I can hide the Div element but haven't been able to find the code to accomplish this when the author of the post is an admin only.更糟糕的是,我可以隐藏 Div 元素,但是当帖子的作者只是管理员时,我无法找到完成此操作的代码。 I can also use the user ID if that works as well to remove the author.我也可以使用用户 ID 来删除作者。 Thanks!谢谢!

function get_user_role($post_authr_id) {
    $user = new WP_User($post_authr_id);
    return array_shift($user->roles);
}

global $post;
$post_authr_id = $post->post_author;
$auhtor_role = get_user_role($post_authr_id);

if($auhtor_role !== 'administrator'){

    //if auhor role is not admin display auhtor name

    /*

        your author display code here

    */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM