在 WordPress 表单中,当您以访客身份留下评论时,会出现一个网站字段来填写您的网址。如果我们填写该框,我们可以通过调用此函数来获取链接
<?php echo get_comment_author_link(); ?>
但是,如果您已登录并且未在您的个人资料中添加该网站,那么当您发表评论时。您的用户名上没有链接。
我想要的是,如果登录的用户没有该网站,将会有一个链接将他们带到他们的个人资料页面,类似于http://www.example.com?author=21
有什么功能我可以使用吗?请帮帮我。谢谢。
将其放入主题的functions.php中;
function force_comment_author_url($comment)
{
// does the comment have a valid author URL?
$no_url = !$comment->comment_author_url || $comment->comment_author_url == 'http://';
if ($comment->user_id && $no_url) {
// comment was written by a registered user but with no author URL
$comment->comment_author_url = 'http://www.example.com/?author=' . $comment->user_id;
}
return $comment;
}
add_filter('get_comment', 'force_comment_author_url');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)