如何用WordPress中的自定义字段重写来宾作者姓名

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

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-rewrite-guest-author-name-with-custom-fields-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值