Drupal 7.
For example no matter what menu block would be added to the header region, how can I make it replace first link (which has .first class) with image link?
So Drupal generates links as <li class=first><a href="#">Home</a></li>
and then apply some function from template.php which would replace it with something like <li class=first><a href="#"><img src='../link.png'></img></a></li>
I found some code which kind of does that, but it needs to enter path to image via Add link under Title field and I don't really need that, the users of the theme won't understand how that works. And it also applies to any links. While I need to switch the very first text link with image link whose path would be given inside template.php
<?php
/**
* Allows for images as menu items.
* Just supply the an image path in the title. The image path will be replaced
* with an img tag. The description is used as alt text and title.
* Implements theme_menu_link().
* Reference: http://chrisshattuck.com/blog/how-use-images-menu-items-drupal-simple-preprocessing-function
*/
function YOUR_THEME_menu_link($variables) {
$element = &$variables['element'];
$pattern = '/\S+\.(png|gif|jpg)\b/i';
if (preg_match($pattern, $element['#title'], $matches) > 0) {
$element['#title'] = preg_replace($pattern,
'<img alt = "' . $element['#localized_options']['attributes']['title'] . '" src = "' . url($matches[0]) . '" />',
$element['#title']);
$element['#localized_options']['html'] = TRUE;
}
return theme_menu_link($variables);
}
?>
I can do that with CSS, but I prefer not (client side reasons).