Globally providing title attribute to links Recently I've been asked by a SEO-managing person to copy the text of all links within main menu into their title attribute. As my menu is run by OM Maximenu and contains mostly Views, it was relatively easy to add it in corresponding view, but I started to wonder if there's a way to globally alter links in such a way. It would have to be performed in PHP level (template.php or a module). I haven't found a hook though like "drupal_link_alter", except for some old Drupal 5 function?

Any insights?
A lot of links end up going through theme_link() at some point (even those that go through the l() function by default); so providing a preprocess function for that theme, that adds a title to any link that doesn't already have one, would be a very good start:

function MYTHEME_preprocess_link(&amp;$vars) {
  // If there is already a title set, and it's not empty, we don't need to continue.
  if (isset($vars['options']['attributes']['title']) &amp;&amp; !empty($vars['options']['attributes']['title'])) {
    return;
  }

  // Otherwise we use the link text as the title.
  $vars['options']['attributes']['title'] = strip_tags($vars['text']);
}


This won't catch links that are outputted directly in HTML, or don't go through l()/theme_link(), but I think you'll struggle to intercept those anyway (it would require some DOM parsing or ugly regex).