Using an image link menu in Drupal 6 instead of text

Sometimes, we don’t want to limit our creativity by just using text in all of the menu items. Sometimes, we would want to use an image as a link in a menu.

For example, you want to have Home as an image link rather than a text link. Here’s a code you can use in your theme’s template.php file.

function phptemplate_menu_item_link($link) {

if ($link['title']==’Home’) {
$link['localized_options']['html'] = TRUE;
$image_path = path_to_theme(). ‘images/home.png’;
$title = ‘Home’;
$link['title'] = theme(’image’, $image_path, $title, $title);
return theme_menu_item_link($link);
}

else {
return theme_menu_item_link($link);
}
}

Tags:

One Response to “Using an image link menu in Drupal 6 instead of text”

  1. Anish Says:

    Hi,

    I tried this, but no luck for me :( Can you please check my code ?

    yourtheme_menu_item_link($link) {
    if (preg_match(’/\.(png|gif|jpg)$/’, $link['title']) ) {
    $link['localized_options']['html'] = TRUE;
    $image_path = path_to_theme(). $link['title'];
    $title = ‘hello’;
    $link['title'] = theme_image($image_path, $title, $title);
    return theme_menu_item_link($link);
    }

    else {
    return theme_menu_item_link($link);
    }
    }

    Thanks!

Leave a Reply

Categories

Interested for a quote?

Business Days: Monday to Friday

Time Zone: GMT +8

Response time: Within 24 hours except for inquiries sent on Fridays.

Contact Us

View our Sample Works