Comment Author Link on Wordpress

2020-03-30 06:24发布

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.

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.

标签: php wordpress
2条回答
何必那么认真
2楼-- · 2020-03-30 07:05

well i guess a workaround is to have a php/mySQL script update the empty database fields in wordpress database to the value you want

查看更多
smile是对你的礼貌
3楼-- · 2020-03-30 07:19

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');
查看更多
登录 后发表回答