1

How do I remove the link to a user's profile on article content? The element is part of the article header and its classname is ".username". I am new to Drupal but not to webdesign; I am just having trouble pinpointing which file to edit.

I tried:

function phptemplate_links($links, $attributes = array()) {
    unset($links['.username']);
    return theme_links($links, $attributes);
}

in my theme template.php file but it did not work.

Just to be clear: I am trying to remove the element but not the text. I still want the user's name to appear, just not the link to the profile page. Also, I am looking for a PHP-based solution, not CSS, and trying to avoid adding any more modules.

Thanks!

  • Specifically for the article node type? – rooby Apr 21 '13 at 4:28
  • Do you want visitors to be able to see profile pages? If not you can remove the permission to access user profiles and then user names will appear as plain text instead of as links. – Alfred Armstrong Apr 21 '13 at 11:53
1

You can't do this with CSS but you can do it without having to add another module.

If you want it exactly the same as default, but without the link, this would be it:

Just add this code to your template.php file in your theme (change YOURTHEME to be your theme name):

/**
 * Override or insert variables into the node template.
 */
function YOURTHEME_preprocess_node(&$variables) {
  $node = $variables['node'];

  if ($node->type == 'article') {
    // This will replace the user name link with the same text but without the
    // link.

    // Set the name to a formatted name that is safe for printing and
    // that won't break tables by being too long. Keep an unshortened,
    // unsanitized version, in case other preprocess functions want to implement
    // their own shortening logic or add markup. If they do so, they must ensure
    // that $variables['name'] is safe for printing.
    $name = format_username($node);
    if (drupal_strlen($name) > 20) {
      $name = drupal_substr($name, 0, 15) . '...';
    }
    $variables['name'] = $name;
    // Display post information only on certain node types.
    if (variable_get('node_submitted_' . $node->type, TRUE)) {
      $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
    }
  }
}

if YOURTHEME_preprocess_node() already exists in your theme just add this to it:

  $node = $variables['node'];

  if ($node->type == 'article') {
    // This will replace the user name link with the same text but without the
    // link.

    // Set the name to a formatted name that is safe for printing and
    // that won't break tables by being too long. Keep an unshortened,
    // unsanitized version, in case other preprocess functions want to implement
    // their own shortening logic or add markup. If they do so, they must ensure
    // that $variables['name'] is safe for printing.
    $name = format_username($node);
    if (drupal_strlen($name) > 20) {
      $name = drupal_substr($name, 0, 15) . '...';
    }
    $variables['name'] = $name;
    // Display post information only on certain node types.
    if (variable_get('node_submitted_' . $node->type, TRUE)) {
      $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
    }
  }
1

You can create node--[content-type].tpl.php for your node and can display the username by $node variable and comment the default $submitted variable.

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.