Search

You are here

Allow images in menu items in Drupal 7

Do you want to show images in menu items in Drupal 7? E.g. a Twitter logo beside some text?

You could (1) use the Menu Icons module or (2) add a simple theming function in your theme.

Add the following theming function to your template.php file in your theme:

<?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'];

An image path (recognized by the ending .png, .gif or .jpg) in the title of the menu item will be replaced with an image tag. E.g. "sites/default/files/images/twitter.png Follow" will show the Twitter image with the text Follow.

Simply want to say your article is as amazing.
The clarity to your put up is just spectacular and i could think you are knowledgeable in this subject.
Well together with your permission allow me to take hold of your feed to
stay up to date with drawing close post. Thank you a million and please
continue the rewarding work.

I have to thank you for the efforts you have put in writing this blog.
I am hoping to check out the same high-grade content from you later on as well.
In fact, your creative writing abilities has inspired me to
get my own, personal site now ;)

Hello There. I found your weblog the usage of msn. That is a really well written article.
I'll make sure to bookmark it and come back to learn extra of your helpful info. Thank you for the post. I will certainly return.

Hello there! I could have sworn I've been to this website before but after going through a few of the posts I realized it's new to me.
Nonetheless, I'm definitely delighted I found it and I'll
be book-marking it and checking back frequently!

You really make it appear really easy together with your presentation but I in finding this topic to be actually something which I think I'd by no means understand. It seems too complicated and very vast for me. I am taking a look forward for your next put up, I will attempt to get the hang of it!

Sorry, my last comment was wrong, this is not working for me only because i'm using Nice Menus module. So here is my question : would you have any tricks to make it work through Nice Menus module ?
thanks in advance

I used this snippet happily until i enabled i18n for my site..
You use the url() function, but that way drupal will add the language prefix to the image's source path, that way you will have 404 for each of them.
Simply use the path as it is, just adding a slash before, without passing through the url() function, will fix the problem.
Thanks, anyway..
Da.

This code isn't working for me i am using drupal 7 i want to display a home image in place of text "home" menu button. I have uploaded the image file on the server and I have replaced my theme with sky .. still not working please help I am new to drupal