开发者

Comment Author Link on 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 do开发者_高级运维n'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.


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');


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜