diff --git a/includes/menu.inc b/includes/menu.inc
index b1d1bdb517cf30d2a3581f6029d040c142197611..92a1325d8fb615e5458dc8d3ce455430cecbf550 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -703,16 +703,30 @@ function theme_menu_item_link($item, $link_item) {
  *
  * @param $mid
  *   The menu item id to render.
+ * @param $theme
+ *   Whether to return a themed link or the link as an array
  */
-function menu_item_link($mid) {
+function menu_item_link($mid, $theme = TRUE) {
   $item = menu_get_item($mid);
   $link_item = $item;
+  $link = '';
 
   while ($link_item['type'] & MENU_LINKS_TO_PARENT) {
     $link_item = menu_get_item($link_item['pid']);
   }
 
-  return theme('menu_item_link', $item, $link_item);
+  if ($theme) {
+    $link = theme('menu_item_link', $item, $link_item);
+  }
+  else {
+    $link = array(
+      '#title' => $item['title'],
+      '#href' => $link_item['path'],
+      '#attributes' => isset($item['description']) ? array('title' => $item['description']) : array()
+    );
+  }
+
+  return $link;
 }
 
 /**
@@ -806,7 +820,7 @@ function theme_menu_local_task($mid, $active, $primary) {
  * @param $pid
  *   The parent menu ID from which to search for children. Defaults to the
  *   menu_primary_menu setting.
- * @return An array containing the themed links as the values. The keys of
+ * @return A nested array of links and their properties. The keys of
  *   the array contain some extra encoded information about the results.
  *   The format of the key is {level}-{num}{-active}.
  *   level is the depth within the menu tree of this list.
@@ -842,18 +856,21 @@ function menu_primary_links($start_level = 1, $pid = 0) {
   if ($pid && is_array($menu['visible'][$pid]) && isset($menu['visible'][$pid]['children'])) {
     $count = 1;
     foreach ($menu['visible'][$pid]['children'] as $cid) {
-      $index = "$start_level-$count";
+      $index = "$start_level-$count-$pid";
       if (menu_in_active_trail_in_submenu($cid, $pid)) {
         $index .= "-active";
       }
-      $links[$index] = menu_item_link($cid);
+      $links[$index] = menu_item_link($cid, FALSE);
       $count++;
     }
   }
 
   // Special case - provide link to admin/menu if primary links is empty.
   if (empty($links) && $start_level == 1 && $pid == variable_get('menu_primary_menu', 0)) {
-    $links['1-1'] = l(t('edit primary links'),'admin/menu');
+    $links['1-1'] = array(
+      '#title' => t('edit primary links'),
+      '#href' => 'admin/menu'
+    );
   }
 
   return $links;
diff --git a/includes/theme.inc b/includes/theme.inc
index 19e0f4b716f7bc3d83d018cf7dae51feb421d3fa..89f388dce76af12606d208911a66be05c0435dee 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -486,17 +486,36 @@ function theme_status_messages() {
  * Return a themed set of links.
  *
  * @param $links
- *   An array of links to be themed.
+ *   A keyed array of links to be themed.
  * @param $delimiter
  *   A string used to separate the links.
  * @return
  *   A string containing the themed links.
  */
 function theme_links($links, $delimiter = ' | ') {
-  if (!is_array($links)) {
-    return '';
+  $output = array();
+
+  if (is_array($links)) {
+    foreach ($links as $key => $link) {
+      //Automatically add a class to each link and convert all _ to - for XHTML compliance
+      if (isset($link['#attributes']) && isset($link['#attributes']['class'])) {
+        $link['#attributes']['class'] .= ' '. str_replace('_', '-', $key);
+      }
+      else {
+        $link['#attributes']['class'] = str_replace('_', '-', $key);
+      }
+
+      if ($link['#href']) {
+        $output[] = l($link['#title'], $link['#href'], $link['#attributes'], $link['#query'], $link['#fragment']);
+      }
+      else if ($link['#title']) {
+        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
+        $output[] = '<span'. drupal_attributes($link['#attributes']) .'>'. $link['#title'] .'</span>';
+      }
+    }
   }
-  return implode($delimiter, $links);
+
+  return implode($delimiter, $output);
 }
 
 /**
diff --git a/modules/aggregator.module b/modules/aggregator.module
index 21ea91e06307bac3b823e19aa096471b01c7d8d0..da6b17fe779f3462a815a2e778c6c3bb113b01c3 100644
--- a/modules/aggregator.module
+++ b/modules/aggregator.module
@@ -1145,7 +1145,13 @@ function aggregator_page_sources() {
       }
     }
     $output .= theme('item_list', $list);
-    $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/sources/'. $feed->fid))) ."</div>\n";
+
+    $link['sources'] = array(
+      '#title' => t('more'),
+      '#href' => 'aggregator/sources/'. $feed->fid
+    );
+
+    $output .= '<div class="links">'. theme('links', $link) ."</div>\n";
   }
   $output .= theme('xml_icon', url('aggregator/opml'));
   $output .= '</div>';
@@ -1245,8 +1251,15 @@ function aggregator_page_categories() {
       }
       $output .= theme('item_list', $list);
     }
-    $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/categories/'. $category->cid))) ."</div>\n";
+
+    $link['categories'] = array(
+      '#title' => t('more'),
+      '#href' => 'aggregator/categories/'. $category->cid
+    );
+
+    $output .= '<div class="links">'. theme('links', $link) ."</div>\n";
   }
+
   $output .= '</div>';
 
   return $output;
diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module
index 21ea91e06307bac3b823e19aa096471b01c7d8d0..da6b17fe779f3462a815a2e778c6c3bb113b01c3 100644
--- a/modules/aggregator/aggregator.module
+++ b/modules/aggregator/aggregator.module
@@ -1145,7 +1145,13 @@ function aggregator_page_sources() {
       }
     }
     $output .= theme('item_list', $list);
-    $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/sources/'. $feed->fid))) ."</div>\n";
+
+    $link['sources'] = array(
+      '#title' => t('more'),
+      '#href' => 'aggregator/sources/'. $feed->fid
+    );
+
+    $output .= '<div class="links">'. theme('links', $link) ."</div>\n";
   }
   $output .= theme('xml_icon', url('aggregator/opml'));
   $output .= '</div>';
@@ -1245,8 +1251,15 @@ function aggregator_page_categories() {
       }
       $output .= theme('item_list', $list);
     }
-    $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/categories/'. $category->cid))) ."</div>\n";
+
+    $link['categories'] = array(
+      '#title' => t('more'),
+      '#href' => 'aggregator/categories/'. $category->cid
+    );
+
+    $output .= '<div class="links">'. theme('links', $link) ."</div>\n";
   }
+
   $output .= '</div>';
 
   return $output;
diff --git a/modules/blog.module b/modules/blog.module
index d1246f31c18e2a61fc4cef6175cbc9c7a9779a6f..01c5fa557ab6f49d4014bb8a2674fc2cc9be085d 100644
--- a/modules/blog.module
+++ b/modules/blog.module
@@ -249,7 +249,11 @@ function blog_link($type, $node = 0, $main = 0) {
 
   if ($type == 'node' && $node->type == 'blog') {
     if (arg(0) != 'blog' || arg(1) != $node->uid) {
-      $links[] = l(t("%username's blog", array('%username' => $node->name)), "blog/$node->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name))));
+      $links['blog_usernames_blog'] = array(
+        '#title' => t("%username's blog", array('%username' => $node->name)),
+        '#href' => "blog/$node->uid",
+        '#attributes' => array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name)))
+      );
     }
   }
 
diff --git a/modules/blog/blog.module b/modules/blog/blog.module
index d1246f31c18e2a61fc4cef6175cbc9c7a9779a6f..01c5fa557ab6f49d4014bb8a2674fc2cc9be085d 100644
--- a/modules/blog/blog.module
+++ b/modules/blog/blog.module
@@ -249,7 +249,11 @@ function blog_link($type, $node = 0, $main = 0) {
 
   if ($type == 'node' && $node->type == 'blog') {
     if (arg(0) != 'blog' || arg(1) != $node->uid) {
-      $links[] = l(t("%username's blog", array('%username' => $node->name)), "blog/$node->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name))));
+      $links['blog_usernames_blog'] = array(
+        '#title' => t("%username's blog", array('%username' => $node->name)),
+        '#href' => "blog/$node->uid",
+        '#attributes' => array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name)))
+      );
     }
   }
 
diff --git a/modules/book.module b/modules/book.module
index 8af126911e0edd044ac2ad4b4ccd9a311356527a..fb61ac0701df2597f19813d01cea0ae90baaf67d 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -58,12 +58,17 @@ function book_link($type, $node = 0, $main = 0) {
   if ($type == 'node' && isset($node->parent)) {
     if (!$main) {
       if (book_access('create', $node)) {
-        $links[] = l(t('add child page'), "node/add/book/parent/$node->nid");
+        $links['book_add_child'] = array(
+          '#title' => t('add child page'),
+          '#href' => "node/add/book/parent/$node->nid"
+        );
       }
       if (user_access('see printer-friendly version')) {
-        $links[] = l(t('printer-friendly version'),
-                     'book/export/html/'. $node->nid,
-                     array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')));
+        $links['book_printer'] = array(
+          '#title' => t('printer-friendly version'),
+          '#href' => 'book/export/html/'. $node->nid,
+          '#attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
+        );
       }
     }
   }
diff --git a/modules/book/book.module b/modules/book/book.module
index 8af126911e0edd044ac2ad4b4ccd9a311356527a..fb61ac0701df2597f19813d01cea0ae90baaf67d 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -58,12 +58,17 @@ function book_link($type, $node = 0, $main = 0) {
   if ($type == 'node' && isset($node->parent)) {
     if (!$main) {
       if (book_access('create', $node)) {
-        $links[] = l(t('add child page'), "node/add/book/parent/$node->nid");
+        $links['book_add_child'] = array(
+          '#title' => t('add child page'),
+          '#href' => "node/add/book/parent/$node->nid"
+        );
       }
       if (user_access('see printer-friendly version')) {
-        $links[] = l(t('printer-friendly version'),
-                     'book/export/html/'. $node->nid,
-                     array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')));
+        $links['book_printer'] = array(
+          '#title' => t('printer-friendly version'),
+          '#href' => 'book/export/html/'. $node->nid,
+          '#attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
+        );
       }
     }
   }
diff --git a/modules/comment.module b/modules/comment.module
index bcea6844ee7ea02f587f09a18ddf1179336e7515..5d8eeaee1dd9376214974ac56ff57784721cc8ca 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -195,19 +195,34 @@ function comment_link($type, $node = 0, $main = 0) {
         $new = comment_num_new($node->nid);
 
         if ($all) {
-          $links[] = l(format_plural($all, '1 comment', '%count comments'), "node/$node->nid", array('title' => t('Jump to the first comment of this posting.')), NULL, 'comment');
+          $links['comment_comments'] = array(
+            '#title' => format_plural($all, '1 comment', '%count comments'),
+            '#href' => "node/$node->nid",
+            '#attributes' => array('title' => t('Jump to the first comment of this posting.')),
+            '#fragment' => 'comment'
+          );
 
           if ($new) {
-            $links[] = l(format_plural($new, '1 new comment', '%count new comments'), "node/$node->nid", array('title' => t('Jump to the first new comment of this posting.')), NULL, 'new');
+            $links['comment_new_comments'] = array(
+              '#title' => format_plural($new, '1 new comment', '%count new comments'),
+              '#href' => "node/$node->nid",
+              '#attributes' => array('title' => t('Jump to the first new comment of this posting.')),
+              '#fragment' => 'new'
+            );
           }
         }
         else {
           if ($node->comment == COMMENT_NODE_READ_WRITE) {
             if (user_access('post comments')) {
-              $links[] = l(t('add new comment'), "comment/reply/$node->nid", array('title' => t('Add a new comment to this page.')), NULL, 'comment_form');
+              $links['comment_add'] = array(
+                '#title' => t('add new comment'),
+                '#href' => "comment/reply/$node->nid",
+                '#attributes' => array('title' => t('Add a new comment to this page.')),
+                '#fragment' => 'comment_form'
+              );
             }
             else {
-              $links[] = theme('comment_post_forbidden', $node->nid);
+              $links['comment_forbidden']['#title'] = theme('comment_post_forbidden', $node->nid);
             }
           }
         }
@@ -220,11 +235,16 @@ function comment_link($type, $node = 0, $main = 0) {
       if ($node->comment == COMMENT_NODE_READ_WRITE) {
         if (user_access('post comments')) {
           if (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
-            $links[] = l(t('add new comment'), "comment/reply/$node->nid", array('title' => t('Share your thoughts and opinions related to this posting.')), NULL, 'comment_form');
+            $links['comment_add'] = array(
+              '#title' => t('add new comment'),
+              '#href' => "comment/reply/$node->nid",
+              '#attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')),
+              '#fragment' => 'comment_form'
+            );
           }
         }
         else {
-          $links[] = theme('comment_post_forbidden', $node->nid);
+          $links['comment_forbidden']['#title'] = theme('comment_post_forbidden', $node->nid);
         }
       }
     }
@@ -670,23 +690,42 @@ function comment_links($comment, $return = 1) {
 
   // If we are viewing just this comment, we link back to the node.
   if ($return) {
-    $links[] = l(t('parent'), comment_node_url(), NULL, NULL, "comment-$comment->cid");
+    $links['comment_parent'] = array(
+      '#title' => t('parent'),
+      '#href' => comment_node_url(),
+      '#fragment' => "comment-$comment->cid"
+    );
   }
 
   if (node_comment_mode($comment->nid) == COMMENT_NODE_READ_WRITE) {
     if (user_access('administer comments') && user_access('post comments')) {
-      $links[] = l(t('delete'), "comment/delete/$comment->cid");
-      $links[] = l(t('edit'), "comment/edit/$comment->cid");
-      $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
+      $links['comment_delete'] = array(
+        '#title' => t('delete'),
+        '#href' => "comment/delete/$comment->cid"
+      );
+      $links['comment_edit'] = array(
+        '#title' => t('edit'),
+        '#href' => "comment/edit/$comment->cid"
+      );
+      $links['comment_reply'] = array(
+        '#title' => t('reply'),
+        '#href' => "comment/reply/$comment->nid/$comment->cid"
+      );
     }
     else if (user_access('post comments')) {
       if (comment_access('edit', $comment)) {
-        $links[] = l(t('edit'), "comment/edit/$comment->cid");
+        $links['comment_edit'] = array(
+          '#title' => t('edit'),
+          '#href' => "comment/edit/$comment->cid"
+        );
       }
-      $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
+      $links['comment_reply'] = array(
+        '#title' => t('reply'),
+        '#href' => "comment/reply/$comment->nid/$comment->cid"
+      );
     }
     else {
-      $links[] = theme('comment_post_forbidden', $comment->nid);
+      $links['comment_forbidden']['#title'] = theme('comment_post_forbidden', $comment->nid);
     }
   }
 
@@ -724,7 +763,14 @@ function comment_render($node, $cid = 0) {
 
       if ($comment = db_fetch_object($result)) {
         $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
-        $output .= theme('comment_view', $comment, module_invoke_all('link', 'comment', $comment, 1));
+        $links = module_invoke_all('link', 'comment', $comment, 1);
+
+        foreach (module_implements('link_alter') as $module) {
+          $function = $module .'_link_alter';
+          $function($node, $links);
+        }
+
+        $output .= theme('comment_view', $comment, $links);
       }
     }
     else {
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index bcea6844ee7ea02f587f09a18ddf1179336e7515..5d8eeaee1dd9376214974ac56ff57784721cc8ca 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -195,19 +195,34 @@ function comment_link($type, $node = 0, $main = 0) {
         $new = comment_num_new($node->nid);
 
         if ($all) {
-          $links[] = l(format_plural($all, '1 comment', '%count comments'), "node/$node->nid", array('title' => t('Jump to the first comment of this posting.')), NULL, 'comment');
+          $links['comment_comments'] = array(
+            '#title' => format_plural($all, '1 comment', '%count comments'),
+            '#href' => "node/$node->nid",
+            '#attributes' => array('title' => t('Jump to the first comment of this posting.')),
+            '#fragment' => 'comment'
+          );
 
           if ($new) {
-            $links[] = l(format_plural($new, '1 new comment', '%count new comments'), "node/$node->nid", array('title' => t('Jump to the first new comment of this posting.')), NULL, 'new');
+            $links['comment_new_comments'] = array(
+              '#title' => format_plural($new, '1 new comment', '%count new comments'),
+              '#href' => "node/$node->nid",
+              '#attributes' => array('title' => t('Jump to the first new comment of this posting.')),
+              '#fragment' => 'new'
+            );
           }
         }
         else {
           if ($node->comment == COMMENT_NODE_READ_WRITE) {
             if (user_access('post comments')) {
-              $links[] = l(t('add new comment'), "comment/reply/$node->nid", array('title' => t('Add a new comment to this page.')), NULL, 'comment_form');
+              $links['comment_add'] = array(
+                '#title' => t('add new comment'),
+                '#href' => "comment/reply/$node->nid",
+                '#attributes' => array('title' => t('Add a new comment to this page.')),
+                '#fragment' => 'comment_form'
+              );
             }
             else {
-              $links[] = theme('comment_post_forbidden', $node->nid);
+              $links['comment_forbidden']['#title'] = theme('comment_post_forbidden', $node->nid);
             }
           }
         }
@@ -220,11 +235,16 @@ function comment_link($type, $node = 0, $main = 0) {
       if ($node->comment == COMMENT_NODE_READ_WRITE) {
         if (user_access('post comments')) {
           if (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
-            $links[] = l(t('add new comment'), "comment/reply/$node->nid", array('title' => t('Share your thoughts and opinions related to this posting.')), NULL, 'comment_form');
+            $links['comment_add'] = array(
+              '#title' => t('add new comment'),
+              '#href' => "comment/reply/$node->nid",
+              '#attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')),
+              '#fragment' => 'comment_form'
+            );
           }
         }
         else {
-          $links[] = theme('comment_post_forbidden', $node->nid);
+          $links['comment_forbidden']['#title'] = theme('comment_post_forbidden', $node->nid);
         }
       }
     }
@@ -670,23 +690,42 @@ function comment_links($comment, $return = 1) {
 
   // If we are viewing just this comment, we link back to the node.
   if ($return) {
-    $links[] = l(t('parent'), comment_node_url(), NULL, NULL, "comment-$comment->cid");
+    $links['comment_parent'] = array(
+      '#title' => t('parent'),
+      '#href' => comment_node_url(),
+      '#fragment' => "comment-$comment->cid"
+    );
   }
 
   if (node_comment_mode($comment->nid) == COMMENT_NODE_READ_WRITE) {
     if (user_access('administer comments') && user_access('post comments')) {
-      $links[] = l(t('delete'), "comment/delete/$comment->cid");
-      $links[] = l(t('edit'), "comment/edit/$comment->cid");
-      $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
+      $links['comment_delete'] = array(
+        '#title' => t('delete'),
+        '#href' => "comment/delete/$comment->cid"
+      );
+      $links['comment_edit'] = array(
+        '#title' => t('edit'),
+        '#href' => "comment/edit/$comment->cid"
+      );
+      $links['comment_reply'] = array(
+        '#title' => t('reply'),
+        '#href' => "comment/reply/$comment->nid/$comment->cid"
+      );
     }
     else if (user_access('post comments')) {
       if (comment_access('edit', $comment)) {
-        $links[] = l(t('edit'), "comment/edit/$comment->cid");
+        $links['comment_edit'] = array(
+          '#title' => t('edit'),
+          '#href' => "comment/edit/$comment->cid"
+        );
       }
-      $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
+      $links['comment_reply'] = array(
+        '#title' => t('reply'),
+        '#href' => "comment/reply/$comment->nid/$comment->cid"
+      );
     }
     else {
-      $links[] = theme('comment_post_forbidden', $comment->nid);
+      $links['comment_forbidden']['#title'] = theme('comment_post_forbidden', $comment->nid);
     }
   }
 
@@ -724,7 +763,14 @@ function comment_render($node, $cid = 0) {
 
       if ($comment = db_fetch_object($result)) {
         $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
-        $output .= theme('comment_view', $comment, module_invoke_all('link', 'comment', $comment, 1));
+        $links = module_invoke_all('link', 'comment', $comment, 1);
+
+        foreach (module_implements('link_alter') as $module) {
+          $function = $module .'_link_alter';
+          $function($node, $links);
+        }
+
+        $output .= theme('comment_view', $comment, $links);
       }
     }
     else {
diff --git a/modules/forum.module b/modules/forum.module
index 6a27f68555e815ee923c2e38b643061d4d1b015d..922df1eb0654962f751aca3bb4d42b4ae179d01d 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -635,8 +635,13 @@ function _forum_parent_select($tid, $title, $child_type) {
   return array('#type' => 'select', '#title' => $title, '#default_value' => $parent, '#options' => $options, '#description' => $description, '#required' => TRUE);
 }
 
-function forum_term_path($term) {
-  return 'forum/'. $term->tid;
+function forum_link_alter(&$node, &$links) {
+  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']);
+    }
+  }
 }
 
 /**
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 6a27f68555e815ee923c2e38b643061d4d1b015d..922df1eb0654962f751aca3bb4d42b4ae179d01d 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -635,8 +635,13 @@ function _forum_parent_select($tid, $title, $child_type) {
   return array('#type' => 'select', '#title' => $title, '#default_value' => $parent, '#options' => $options, '#description' => $description, '#required' => TRUE);
 }
 
-function forum_term_path($term) {
-  return 'forum/'. $term->tid;
+function forum_link_alter(&$node, &$links) {
+  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']);
+    }
+  }
 }
 
 /**
diff --git a/modules/node.module b/modules/node.module
index fb8bd70359b58b566cfda81d0ffbf2a1edef03b3..3eb21d6387c8f19e473d5e1a8cbd2f8736885d8d 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -536,6 +536,11 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
   node_invoke_nodeapi($node, 'view', $teaser, $page);
   if ($links) {
     $node->links = module_invoke_all('link', 'node', $node, !$page);
+
+    foreach (module_implements('link_alter') AS $module) {
+      $function = $module .'_link_alter';
+      $function($node, $node->links);
+    }
   }
   // unset unused $node part so that a bad theme can not open a security hole
   if ($teaser) {
@@ -810,7 +815,11 @@ function node_link($type, $node = 0, $main = 0) {
     }
 
     if ($main == 1 && $node->teaser && $node->readmore) {
-      $links[] = l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));
+      $links['node_read_more'] = array(
+        '#title' => t('read more'),
+        '#href' => "node/$node->nid",
+        '#attributes' => array('title' => t('Read the rest of this posting.'))
+      );
     }
   }
 
diff --git a/modules/node/node.module b/modules/node/node.module
index fb8bd70359b58b566cfda81d0ffbf2a1edef03b3..3eb21d6387c8f19e473d5e1a8cbd2f8736885d8d 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -536,6 +536,11 @@ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
   node_invoke_nodeapi($node, 'view', $teaser, $page);
   if ($links) {
     $node->links = module_invoke_all('link', 'node', $node, !$page);
+
+    foreach (module_implements('link_alter') AS $module) {
+      $function = $module .'_link_alter';
+      $function($node, $node->links);
+    }
   }
   // unset unused $node part so that a bad theme can not open a security hole
   if ($teaser) {
@@ -810,7 +815,11 @@ function node_link($type, $node = 0, $main = 0) {
     }
 
     if ($main == 1 && $node->teaser && $node->readmore) {
-      $links[] = l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'));
+      $links['node_read_more'] = array(
+        '#title' => t('read more'),
+        '#href' => "node/$node->nid",
+        '#attributes' => array('title' => t('Read the rest of this posting.'))
+      );
     }
   }
 
diff --git a/modules/statistics.module b/modules/statistics.module
index f6510221e797987d74abb2b5ea41118b30cb7f5d..67dfa76453aa6aef5b6675fd34e6f99f885e7f38 100644
--- a/modules/statistics.module
+++ b/modules/statistics.module
@@ -99,7 +99,7 @@ function statistics_link($type, $node = 0, $main = 0) {
   if ($type != 'comment' && user_access('view post access counter')) {
     $statistics = statistics_get($node->nid);
     if ($statistics) {
-      $links[] = format_plural($statistics['totalcount'], '1 read', '%count reads');
+      $links['statistics_counter']['#title'] = format_plural($statistics['totalcount'], '1 read', '%count reads');
     }
   }
 
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index f6510221e797987d74abb2b5ea41118b30cb7f5d..67dfa76453aa6aef5b6675fd34e6f99f885e7f38 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -99,7 +99,7 @@ function statistics_link($type, $node = 0, $main = 0) {
   if ($type != 'comment' && user_access('view post access counter')) {
     $statistics = statistics_get($node->nid);
     if ($statistics) {
-      $links[] = format_plural($statistics['totalcount'], '1 read', '%count reads');
+      $links['statistics_counter']['#title'] = format_plural($statistics['totalcount'], '1 read', '%count reads');
     }
   }
 
diff --git a/modules/taxonomy.module b/modules/taxonomy.module
index 29ccd3ae0aed3f0d4cf42f7f3036a05d1d1498c8..d917c751180d2967600cd28733462dc1a395d870 100644
--- a/modules/taxonomy.module
+++ b/modules/taxonomy.module
@@ -29,19 +29,22 @@ function taxonomy_link($type, $node = NULL) {
     $links = array();
     if (array_key_exists('taxonomy', $node)) {
       foreach ($node->taxonomy as $term) {
-        $links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
+        $links['taxonomy_term_'. $term->tid] = array(
+          '#title' => $term->name,
+          '#href' => 'taxonomy/term/'. $term->tid,
+          '#attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
+        );
       }
     }
-    return $links;
-  }
-}
 
-function taxonomy_term_path($term) {
-  $vocabulary = taxonomy_get_vocabulary($term->vid);
-  if ($vocabulary->module != 'taxonomy' && $path = module_invoke($vocabulary->module, 'term_path', $term)) {
-    return $path;
+    // We call this hook again because some modules and themes call taxonomy_link('taxonomy terms') directly
+    foreach (module_implements('link_alter') AS $module) {
+      $function = $module .'_link_alter';
+      $function($node, $links);
+    }
+
+    return $links;
   }
-  return 'taxonomy/term/'. $term->tid;
 }
 
 /**
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 29ccd3ae0aed3f0d4cf42f7f3036a05d1d1498c8..d917c751180d2967600cd28733462dc1a395d870 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -29,19 +29,22 @@ function taxonomy_link($type, $node = NULL) {
     $links = array();
     if (array_key_exists('taxonomy', $node)) {
       foreach ($node->taxonomy as $term) {
-        $links[] = l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description)));
+        $links['taxonomy_term_'. $term->tid] = array(
+          '#title' => $term->name,
+          '#href' => 'taxonomy/term/'. $term->tid,
+          '#attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
+        );
       }
     }
-    return $links;
-  }
-}
 
-function taxonomy_term_path($term) {
-  $vocabulary = taxonomy_get_vocabulary($term->vid);
-  if ($vocabulary->module != 'taxonomy' && $path = module_invoke($vocabulary->module, 'term_path', $term)) {
-    return $path;
+    // We call this hook again because some modules and themes call taxonomy_link('taxonomy terms') directly
+    foreach (module_implements('link_alter') AS $module) {
+      $function = $module .'_link_alter';
+      $function($node, $links);
+    }
+
+    return $links;
   }
-  return 'taxonomy/term/'. $term->tid;
 }
 
 /**
diff --git a/modules/upload.module b/modules/upload.module
index c575d1d79389db6162475033feafc04a2f4bb0bc..ca01ac7002f9b60303d129c76a8d68ceb52335c3 100644
--- a/modules/upload.module
+++ b/modules/upload.module
@@ -53,7 +53,12 @@ function upload_link($type, $node = 0, $main = 0) {
       }
     }
     if ($num_files) {
-      $links[] = l(format_plural($num_files, '1 attachment', '%count attachments'), "node/$node->nid", array('title' => t('Read full article to view attachments.')), NULL, 'attachments');
+      $links['upload_attachments'] = array(
+        '#title' => format_plural($num_files, '1 attachment', '%count attachments'),
+        '#href' => "node/$node->nid",
+        '#attributes' => array('title' => t('Read full article to view attachments.')),
+        '#fragment' => 'attachments'
+      );
     }
   }
 
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index c575d1d79389db6162475033feafc04a2f4bb0bc..ca01ac7002f9b60303d129c76a8d68ceb52335c3 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -53,7 +53,12 @@ function upload_link($type, $node = 0, $main = 0) {
       }
     }
     if ($num_files) {
-      $links[] = l(format_plural($num_files, '1 attachment', '%count attachments'), "node/$node->nid", array('title' => t('Read full article to view attachments.')), NULL, 'attachments');
+      $links['upload_attachments'] = array(
+        '#title' => format_plural($num_files, '1 attachment', '%count attachments'),
+        '#href' => "node/$node->nid",
+        '#attributes' => array('title' => t('Read full article to view attachments.')),
+        '#fragment' => 'attachments'
+      );
     }
   }