How can I edit the user profile template in Drupal 7?

I've created a module called sporthron in my project.

sporthron.module contains :

 * Implements hook_theme().
function sporthron_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['user_profile'] = array(
    'template' => 'user-profile',
    'path' => drupal_get_path('module', 'sporthron') . '/templates',
  return $theme;

And here is the path to the template : /sites/all/modules/sporthron/templates/user-profile.tpl.php which contains :

<div class="profile"<?php print $attributes; ?>>
  <?php print render($user_profile); ?>


But this template is never used. Whatever edit I made is not applied.

And yes my module is enabled. Do you know how can I apply this template

  • change the location of your template sites/all/themes/your_theme/templates/user-profile.tpl.php – user52318 Jan 4 '16 at 8:59
  • @Vicky8888 Why should I move to this directory if I'm using a module and not a theme? – Splinteer Jan 4 '16 at 9:42

Try to implement the hook_theme_registry_alter()

 * Implements hook_theme_registry_alter().
function sporthron_theme_registry_alter(&$theme_registry) {

  $module_path = drupal_get_path('module', 'sporthron');

  // Find all .tpl.php files in this module's folder recursively.
  $template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path);
  // Iterate through all found template file objects.
  foreach ($template_file_objects as $key => $template_file_object) {
    // If the template has not already been overridden by a theme.
    if (!isset($theme_registry[$key]['theme path']) || !preg_match('#/themes/#', $theme_registry[$key]['theme path'])) {
      // Alter the theme path and template elements.
      $theme_registry[$key]['theme path'] = $module_path;
      $theme_registry[$key] = array_merge($theme_registry[$key], $template_file_object);
      $theme_registry[$key]['type'] = 'module';

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.