在 Wordpress 上评论作者链接 [英] Comment Author Link on Wordpress
问题描述
在 wordpress 表单中,当您以访客身份发表评论时,会有一个网站字段来填写您的网址.如果我们填写那个框,我们可以通过调用这个函数来获取链接
At the wordpress form, when you leave comment as guest, there's a website field to fill your web address. If we fill in that box, we can get the link by calling this function
<?php echo get_comment_author_link(); ?>
但是,如果您已登录并且没有在您的个人资料中添加该网站,则在发表评论时.您的用户名上没有链接.
But if you are logged in and you don't add the website at your profile, when you leave comment. It doesn't have the link on your username.
我想要的是,如果登录用户没有该网站,则会有一个链接,将他们带到他们的个人资料页面,类似于 http://www.example.com?author=21
What I want is, if the logged-in user doesn't have the website, there will be the link which will be carry them to their profile page which is something like http://www.example.com?author=21
有什么我可以使用的功能吗?请帮帮我.谢谢.
Is there any function that i can use out there ? Please help me out. Thank you.
推荐答案
把这个放到你主题的functions.php;
Drop this in your theme's 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');
这篇关于在 Wordpress 上评论作者链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!