I strongly need to edit some parts of the comments left by the users, I want to add a link to the commenter's author.php page if he/she is a registered user by placing a text link somewhere next to his/her name.
I've this code <?php wp_list_comments(); ?>
but I wonder if it's possible to have the full code instead to replace it in comments.php
Thanks!
2 Answers
This function replaces the comment author's link with the comment author's profile page, if the comment author is a registered user. Otherwise, the standard WordPress comment author link is displayed.
This function is not mine and has been found googling.
function graphene_comment_author_profile_link(){
/* Get the comment author information */
global $comment;
$comment_ID = $comment->user_id;
$author = get_comment_author( $comment_ID );
$url = get_comment_author_url( $comment_ID );
/* Return the default WordPress comment author link if comment author is not
a registered user */
if ($comment_ID == 0){
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
} else {
/* Return the link to the comment author's profile age if otherwise */
$return = '<a href="'.home_url().'/?author='.$comment_ID.'">'.$author.'</a>';
}
return $return;
}
add_filter('get_comment_author_link', 'graphene_comment_author_profile_link');
the function wp_list_comments()
has a 'callback' parameter; using a callback function should allow you to edit the code as you described.
for example see in the default theme Twenty Eleven how it is used;
in comments.php:
wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) );
the actual functions code is in functions.php, starting with:
function twentyeleven_comment( $comment, $args, $depth ) {
-
Thanks Michael but I found a function that makes the name of the registered user linking to his/her profile without modifying anything else. Mar 20, 2013 at 16:41