0

I can display the current user's avatar alongside the comment form when posting a new comment with

$current_user = wp_get_current_user();
if ( ($current_user instanceof WP_User) ) {
  echo get_avatar( $current_user->user_email, 32 );
  }

,but how could I bind the avatar to the comment form if I want to reply to another comment when the onclick addComment.moveForm is fired? The avatar should move along with the form as it moves.

I would be very grateful if someone can point me in the right direction how to dynamically alter the comment form. Documentation on customizing the comment form at Wordpress.org is really poor and I have had a hard time finding any useful info around the internet as well.

2

I'll answer myself. Add the following somewhere in functions.php or make it into a plugin:

add_action( 'comment_form_logged_in_after', 'psot_comment_form_avatar' );
add_action( 'comment_form_after_fields', 'psot_comment_form_avatar' );
function psot_comment_form_avatar()
{
  ?>
   <div class="comment-avatar">
     <?php 
     $current_user = wp_get_current_user();
     if ( ($current_user instanceof WP_User) ) {
        echo get_avatar( $current_user->user_email, 32 );
     }
     ?>
   </div>
<?php
}

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.