hook_link_alter

5 core.php hook_link_alter(&$node, &$links)
6 core.php hook_link_alter(&$links, $node, $comment = NULL)

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.

Parameters

$links: Nested array of links for the node or comment keyed by providing module.

$node: A node object.

$comment: An optional comment object if the links are comment links. If not provided, the links are node links.

See also

hook_link()

Related topics

4 functions implement hook_link_alter()

5 invocations of hook_link_alter()

File

developer/hooks/core.php, line 1046
These are the hooks that are invoked by the Drupal core.

Code

function hook_link_alter(&$links, $node, $comment = NULL) {
  foreach ($links as $module => $link) {
    if (strstr($module, 'taxonomy_term')) {
      // Link back to the forum and not the taxonomy term page
      $links[$module]['href'] = str_replace('taxonomy/term', 'forum', $link['href']);
    }
  }
}

Comments

Drupal 7

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

example to reorder a link (move it to the end of the list)

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);
}

Changes within Drupal 6

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.

Login or register to post comments