Is there an alternative to make the login box that turns into the default user panel (My Account, Administer etc.) display the user's profile picture above the username?

2 Answers 2


There are actually two separate blocks, User login that is displayed only to anonymous users and Navigation that only gets displayed once user has logged in. You are interested in modifying the latter one.

Unfortunately, there's no hook_block_alter() around that you could use to modify the block from a custom module. However, you can do so from within your theme just before the block gets displayed.

Just pop the following function into YOURTHEME's template.php and it should work. Please, note, this adds the user picture to the top of the block content, just below the user name.

function YOURTHEME_preprocess_block(&$vars) {
  $block =& $vars['block'];
  if ($block->module == 'user' && $block->delta == 1) {
    // Navigation block.
    $block->content = theme('user_picture', $vars['user']) . $block->content;

If you want it above the username, just replace $block->content with $block->subject.

Or, even better, just create another block, place it above the Navigation, make it only visible specifically to authenticated user role, set the Body title to <none>, and Block body to:

global $user;    
print theme('user_picture', $user);

Make sure to enable the PHP filter module first and use PHP code filter for the Block body input.

  • This is perfect thanks mate! Just one little issue, it's outputting two of them. I'll post a fix to this specific case soon if I find it. Commented Jul 28, 2011 at 11:46
  • Also, not sure if this shows a default picture if the user has no picture selected. Commented Jul 28, 2011 at 12:09
  • That should be easy to figure out. :-)
    – Jan Tomka
    Commented Jul 28, 2011 at 12:16
  • I have the default set, and it shows in their profiles, but not on the side in the block. So I think it believes if no picture is set, it is NULL, so it won't render it in PHP (nothing in the code to show it is printing it). As for the double picture, still working on that :) Commented Jul 28, 2011 at 12:34
  • I tested it and seems to work okay here. The theme('user_picture') function takes care of everything. Let me know how you go.
    – Jan Tomka
    Commented Jul 28, 2011 at 12:55

You could use Views that would give you a more flexible option, because you can add any fields from the user using the Views UI. You would need to:

  1. Create a View that display Users
  2. Add a contextual filter for the Uid.
  3. Set the configurations of contextual filter's 'When the filter value is NOT in the URL' options to 'Provide default argument - User ID from logged in user'.
  4. Add the fields you need, in your case User Picture and Name.
  5. Add a block display and display the block wherever you want/
  • The problem with creating a view is that each page has to call the view which can get expensive.
    – Adam S
    Commented Jul 27, 2011 at 14:20
  • You can always use something like: drupal.org/project/views_content_cache or Boost, Varnish, etc. But I know what you mean, it is more expensive, but a lot more flexible too and relatively easier for a beginner.
    – ipwa
    Commented Jul 27, 2011 at 15:26
  • @ipwa : Just found this helpful post, thank you ! Can you be more specific when you say : Add a contextual filter for the Uid. ? Can't find it. Thank you.
    – user117283
    Commented May 9, 2012 at 1:11
  • It's in the advanced sections of views, have a look at: metaltoad.com/blog/using-drupal-contextual-filters-views or dev.nodeone.se/node/772
    – ipwa
    Commented May 11, 2012 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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