\hook_link_alter
function
Perform alterations before links on a node or comment are rendered.

Perform alterations before links on a node or comment are rendered.

One popular use of this hook is to modify/remove links from other modules. If you want to add a link to the links section of a node or comment, use hook_link() instead.

Comments

matt2000’s picture

In Drupal 7, links can be modified in hook_node_view_alter().

liquidcms’s picture

i don't agree that hook_node_view_alter() is a valid replacement for this in D7 as it only runs when displaying a node; which doesn't include many pages. So far i haven't found a decent hook to do this in D7.

xandeadx’s picture

hook_entity_view_alter()

Alan D.’s picture

This can be done at the theme layer too. Use THEMENAME_links() for all links, or the theme suggestions to target specific links.

/**
 * Intercepts the node links to alter the user blog links.
 * @param unknown $variables
 * @return string
 */
function THEMENAME_links__node($variables) {
  $links = &$variables['links'];
  if (isset($links['blog_usernames_blog'])) {
    $links['blog_usernames_blog'] = array(
      'title' => t('Blogs'),
      'href' => 'blog',
      'attributes' => array('Read the latest blog entries.'),
    );
  }
  return theme_links($variables);
}
boran’s picture

function mymodule_link_alter(&$links, $node, $comment = NULL) {
// move stats to the end
$move=$links['statistics_counter'];
unset($links['statistics_counter']);
$links['statistics_counter']=$move;
//dsm($links);
}

meustrus’s picture

Prior to Drupal 6.16, hook_link_alter was never used for comments except with single view (such as when replying to a specific comment). The optional $comment variable was added in Drupal 6.17. These changes were made based on #374463: Alter comment links.