1

In the functions.php file for my theme the .commentslist shows a gravatar and if the user fills in a url in the comment form, you get a

comment_author_link()

Which prints a link with the name.

I want to put a link around the .avatar image IF there is a link. There is zip/zilch in the resources (https://developer.wordpress.org/?s=comment_author&post_type[]=wp-parser-function&post_type[]=wp-parser-hook&post_type[]=wp-parser-class&post_type[]=wp-parser-method).

It would be like this but this doesn't work:

<?php if ( has_comment_author_link() ) : ?>
  <a href="<?php echo comment_author_url();?>" target="_blank">
<?php endif; ?>

   <?php echo get_avatar( $comment, $size='75' ); ?>

<?php if ( has_comment_author_link() ) : ?>
  </a>
<?php endif; ?>

But there is no such "has_comment_author_link" and I don't know how to create this.

Thanks!

4

Try this:

if( get_comment_author() == get_comment_author_link() )
    echo get_avatar( $comment, $size='75' );
else
    echo '<a href="' . get_comment_author_url . '">' . get_avatar( $comment, $size='75' ) . '</a>';
| improve this answer | |

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.