Have you ever had a guest post on your blog? How do you go about giving the author full credit? We have seen many sites where they add an author profile box either above the post or below the post. But even with the guest author box, the author name field would still show the site author. Some bloggers create entire new author profiles for their guest authors in order to display the right name. We think that it is pointless to create extra user profiles if you know that this guest author will only post once.
您是否曾经在博客上发表过嘉宾帖子? 您如何才能给予作者充分的信誉? 我们已经看到许多站点,他们在帖子上方或帖子下方添加了作者个人资料框。 但是即使使用来宾作者框,作者姓名字段仍将显示站点作者。 一些博客作者为其来宾作者创建整个新作者个人资料,以显示正确的名称。 我们认为,如果您知道该来宾作者只会发帖一次,那么创建额外的用户个人资料毫无意义。
The trick we are sharing in this article will allow you to show guest author’s name by simply entering a custom field in your post.
我们在本文中分享的技巧将允许您通过在帖子中输入自定义字段来显示来宾作者的姓名。
Open your functions.php file and paste the codes below:
打开您的functions.php文件,并粘贴以下代码:
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );
function guest_author_name( $name ) {
global $post;
$author = get_post_meta( $post->ID, 'guest-author', true );
if ( $author )
$name = $author;
return $name;
}
Now every time that you are posting a guest post, just make sure that you add a custom field called guest-author and it will replace the author’s name with the text that you put in that custom field.
现在,每次发布来宾帖子时,只需确保添加一个名为guest-author的自定义字段,它将使用在该自定义字段中输入的文本替换作者的姓名。
Example:
例:
![Adding guest author name in the custom field Adding guest author name in the custom field](https://i-blog.csdnimg.cn/blog_migrate/eeb95def90d8b6d1195bba4da5c0c547.png)