Profile picture for user admin
Daniel Sipos
05 Nov 2012

So it’s actually not so difficult to have the user image display next to the comment form. All you have to do is modify a bit the comment-wrapper.tpl.php file. For this, I recommend overriding the template file in your theme rather than modifying the original file found in the core comment module.

OK, so once you opened the file, find these lines:

<?php if ($content['comment_form']): ?>
<h2 class="title comment-form">
<?php print t('Add new comment'); ?></h2>

Below that, add the following code:

<div class="user-image">
<?php
if($logged_in) {
  $user = user_load($user->uid);
  print theme('image_style', array('style_name' => 'thumbnail', 'path' => $user->picture->uri));
}
?>
</div>

This code creates a DIV with the class name user-image that you can later control with css and position relative to the comment form itself however you want.

Inside the DIV, the code checks to see if whoever is viewing the comment form is in fact a user who is logged in. If this is the case, using the function user_load, the $user variable becomes an instance of the logged user’s object.

Next, the theme function prints out the thumbnail image style of this user’s picture. Here you can change thumbnail to any image style you may have declared with Image Cache.

All you need then is to control the DIV you created with css and position the image however you want. This of course depends on your theme and how your comment form looks like. You can also go in a bit deeper into the theme layer and take full control over how the comment form is displayed on the page.

Hope this helps.

Profile picture for user admin

Daniel Sipos

CEO @ Web Omelette

Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.

Contact us

Comments

Mar2zz 06 Nov 2013 15:00

Thank you for this tut. I am

Thank you for this tut. I am trying to get the userpicture there but I think my theme isn't processing the user variable to comment-wrapper.tpl.php.

The resulting div above the form is this:

Is there any solution for this?

hamed.azizi 17 Jun 2014 10:40

how to display anonymous user picture

hi
thanks for best articles.
i will display one image for anonymous user's comment and how to link user's website in comment, how to do?

Add new comment