1

By default user picture output markup looks like this:

<div class="user-picture">
    <a href="/user/username" class="active">
        <img class="img-responsive" src="http://www.example.com/sites/example.com/files/styles/profile_page/public/pictures/picture-1-1420552205.jpg?itok=3Kt4fK7H" alt="user avatar username" title="user avatar username" />
    </a>
</div>

I need change markup of user picture output to something like this:

<div class="user-picture">
    <img src="http://www.example.com/sites/example.com/files/styles/profile_page/public/pictures/picture-1-1420552205.jpg?itok=3Kt4fK7H" alt="" />
</div>

Remove unnecessary markup. But question is how?

I have read:

The user-profile.tpl.php file won´t be recognized in my Drupal 7 installation

Changing user picture HTML output on user profile

Will be very appriciate for helping me out.

1

In the core user module you can find user-picture.tpl.php. Copy this file to your active theme, edit it and be sure to clear cache.

If you need to go deeper, put this in your theme's template.php. Original can be found in user.module.

function yourthemename_preprocess_user_picture(&$variables) {
  $variables['user_picture'] = '';
  if (variable_get('user_pictures', 0)) {
    $account = $variables['account'];
    if (!empty($account->picture)) {
      // @TODO: Ideally this function would only be passed file objects, but
      // since there's a lot of legacy code that JOINs the {users} table to
      // {node} or {comments} and passes the results into this function if we
      // a numeric value in the picture field we'll assume it's a file id
      // and load it for them. Once we've got user_load_multiple() and
      // comment_load_multiple() functions the user module will be able to load
      // the picture files in mass during the object's load process.
      if (is_numeric($account->picture)) {
        $account->picture = file_load($account->picture);
      }
      if (!empty($account->picture->uri)) {
        $filepath = $account->picture->uri;
      }
    }
    elseif (variable_get('user_picture_default', '')) {
      $filepath = variable_get('user_picture_default', '');
    }
    if (isset($filepath)) {
      $alt = t("@user's picture", array('@user' => format_username($account)));
      // If the image does not have a valid Drupal scheme (for eg. HTTP),
      // don't load image styles.
      if (module_exists('image') && file_valid_uri($filepath) && $style = variable_get('user_picture_style', '')) {
        $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
      }
      else {
        $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt));
      }
      if (!empty($account->uid) && user_access('access user profiles')) {
        $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
        $variables['user_picture'] = l($variables['user_picture'], "user/$account->uid", $attributes);
      }
    }
  }
} 
4
  • I already did this, but print render($user_profile); is an array with whole bunch of params, question is how to preprocess output of user's picture markup
    – DeN
    Jan 16 '15 at 21:49
  • @DeN See the first paragraph - copying the core user-profile.tpl to your theme's folder and making the changes there would be simplest. If you need to do it in a module only, implement hook_theme_registry_alter() and point the template path for that theme function to a file under your module's control
    – Clive
    Jan 16 '15 at 22:23
  • @Maarten De Block thank you for answer, this is correct solution. But i incorrectly formulate my question. Reason this prerocess don't work in my case is using Dispaly Suit module for user profiles output. DS preprocess this fields by itself and determinate Drupal default layout for this field.
    – DeN
    Jan 17 '15 at 8:40
  • Have you tried drupal.org/project/devel_themer ? You can discover the used tpl's and theming functions. It also suggests ways to override them. Jan 17 '15 at 20:36

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.