How to programmatically add links to the links variable I am using Drupal 6 and would like to modify the $links variable to include other links programmatically. I have searched high and low on Google on how to do this to no avail. Does someone know how to do this?
Drupal 6

In Drupal 6, you can't use hooks or alter hooks inside themes, so you'll need to create a custom module to modify the links. Once done, you'll want to implement hook_link() (if you're creating a new link) or hook_link_alter() (if you want to modify an existing link).

Adding a new link:

example_link($type, $object, $teaser = FALSE) {
  $links = array();
  // Add a custom link to nodes
  if ($type == 'node') {
    $links['example_mylink'] = array(
      'title' =&gt; t('Test link'),
      'href' =&gt; 'foo',
      'attributes' =&gt; array(
        'title' =&gt; 'Test link',
      ),
    );
  }
  return $links;
}


Modifying existing links:

example_link_alter(&amp;$links, $node, $comment = NULL) {
  // Remove the read more link
  unset($links['node']['node_read_more']);

  // Change the title of the read more link
  $links['node']['node_read_more']['title'] = t('More information');

  // Move read more link to first slot
  $link_read_more = $links['node']['node_read_more'];
  unset($links['node']['node_read_more']);
  $links = $links['node'];
  $links['node'] = array(
    'node_read_more' =&gt; $link_read_more,
  ) + $links;

  // Move link to the last slot
  $link_read_more = $links['node']['node_read_more'];
  unset($links['node']['node_read_more']);
  $links['node']['node_read_more'] = $link_read_more;
}


Drupal 7

In Drupal 7, this is a little more straightforward, as themes can implement alter hooks. The alter hook you're looking for is hook_node_view_alter():

function example_node_view_alter(&amp;$build) {
  // Remove the read more link
  unset($build['links']['node']['#links']['node-readmore']);

  // Add your own custom link
  $build['links']['node']['#links']['example-mylink'] = array(
    'title' =&gt; t('Test link'), 
    'href' =&gt; 'foo', 
    'html' =&gt; TRUE, 
    'attributes' =&gt; array(
      'title' =&gt; 'Test link',
    ),
  );

  // Move read more link to first slot
  $link_read_more = $build['links']['node']['#links']['node_read_more'];
  unset($build['links']['node']['#links']['node_read_more']);
  $links = $build['links']['node']['#links'];
  $build['links']['node']['#links'] = array(
    'node_read_more' =&gt; $link_read_more,
  ) + $links;

  // Move link to the last slot
  $link_read_more = $build['links']['node']['#links']['node_read_more'];
  unset($build['links']['node']['#links']['node_read_more']);
  $build['links']['node']['#links']['node_read_more'] = $link_read_more;
}


You can place this directly in your template.php file.