1

I am making theme. and in my custom post type comment, I using

wp_list_comments( array(
    'style'       => 'div',
    'short_ping'  => true,
    'avatar_size' => 0,
    'reply_text'  => 'reply',
) );

This works good. but, when I click the user's name(who wrote the comment), this makes move to his website. But I want to move to his author's page(author.php).

Is this possible? Can you give me some help? Thank you.

1

There are many ways to do this.

Using callback param

One of methods would be using the callback param of wp_list_comments.

This function takes 3 params: $comment, $args and $depth and using it you can create custom HTML code for comments.

There is an example showing how to use this callback in Codex or you can find such callbacks in TwentyX themes.

Using get_comment_author_url filter

But if you want to modify only the URL for authors, then there's an easier and cleaner way and I would definitely prefer this solution.

You can use get_comment_author_url filter as showed below:

function use_author_link_as_comment_author_url( $url, $id, $comment ) {
    if ( $comment->user_id ) {
        return get_author_posts_url( $comment->user_id );
    }
    return $url;
}
add_filter( 'get_comment_author_url', 'use_author_link_as_comment_author_url', 10, 3 );
  • 1
    Wow. Thank you. This is really that I need and works good. I hope you have a cool week. – JJang Jun 12 '18 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.