1

I have a menu in my page that I have created. I have a link called 'Home', and I want an image to be there for only this link. I saw many modules for Drupal 6. Is there any hook or module in Drupal 7 to do this?

3

I am answering my own question, as I googled and found something, mixed it and carved my own way to do it.

function mytheme_menu_link(array $variables) {
  global $base_path;    
  $element = $variables['element'];
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);

  if($element['#title'] == 'Home') {
    $element['#localized_options']['html'] = TRUE;
    $get = '<img src="' . $base_path . drupal_get_path('theme', 'arras') . '/linkback.png" style="vertical-align: middle;" alt="' . $element['#title'] . '" title="' . $element['#title'] . '" />';
    $output1 = l($get,$element['#href'], $element['#localized_options']);
    return '<li' . drupal_attributes($element['#attributes']) . '>' .$output1    . "</li>\n";   
  } else {
    return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . "</li>\n";
  }
}
| improve this answer | |
  • In which page should this be pasted? – user7441 May 17 '12 at 10:47
  • In template.php and replace mytheme with the machine name of your theme. – Ben Swinburne May 17 '12 at 10:54
  • how to add the image? – Bala Feb 17 '13 at 10:12
1

To tweak the answer of Hacker:

If you use fontawesome you could use these nice icons. Then you don´t need to worry about image upload...

The code in yout tempate.php could look like this:

function THEME_menu_link(array $variables) {
  global $base_path;    
  $element = $variables['element'];
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);

  if($element['#title'] == 'Home') {

$element['#localized_options']['html'] = TRUE;
$get = '<i class="fa fa-home fa-lg"></i>';
$output1 = l($get,$element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' .$output1    . "</li>\n";   
  } else {
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . "</li>\n";
  }
}

See The Icon library of fontawsome for more examples for the classname (fa fa-home fa-lg)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.