Add class-element to a link though a module (or can I implement theme_link in a module instead of in a theme)? I'm the developer and maintainer of a module on the Drupal website. It implements an API so that a certain third party service can be easily integrated in Drupal.

I'm currently having the following problem: I need to add a class-element to the logout link. So my module has to arrange that all the these links &lt;a href="/user/logout"&gt;Log out&lt;/a&gt; becomes the following: &lt;a href="/user/logout" class="mymodule"&gt;Log out&lt;/a&gt;

For the logout link in a menu it's easy, I have to implement hook_menu_link_alter(). 

However, I also want to catch all occurences where somebody is using l("Log out", "/user/logout"). The latter function calls theme_link, so if I would implement that, I think it could solve my problem.

So my questions are:


Can I implement theme_link in a module? If so, can somebody tell me how to do this?
Is there another way in which the above could be accomplished by means of a module?
What I understand is that you want to have a class in every link that comes on the site.
I believe, you can achieve this by skinr module - https://drupal.org/project/skinr, which not only adds up classes but also provides you UI to achieve the same.

Also, in module, you can try this.

/**
 * Implements hook_preprocess_HOOK
 */
function MODULENAME_preprocess_menu_link (&amp;$variables) {
  if ($variables['element']['#original_link']['menu_name'] == 'main-menu') {
    $variables['element']['#title'] = '&lt;i class="icon-' . _sanitize_words($variables['element']['#title']) . '"&gt;&lt;/i&gt;' . $variables['element']['#title'];
  }
}


The above could should work, Worked for me atleast :)