Want to use the main menu module with images?

If you have ever wanted to use images as menu items without hacking the main menu module this is for you. You can do this all in the template. First turn on output buffering, then send the buffer to a callback function which will find the menu links and swap them out for your image links.

Here are the steps. Open the index.php file for the template you want to use and right before the HTML tag put in the php function ob_start("callback") - callback being the name of the function you will use - and at the very end of the file put in ob_end_flush(). Now just include the callback function somewhere before you start the buffer and you're done.

Here's what the function does: First it will load info on every menu item. Then for each menu item it will check the parameters to see if a menu image has been assigned - in the administrator, choose to edit the menu item and under parameters assign an image from the images/stories directory. Usually if an image is assigned to that parameter it will show up to either the left or right of the link. This changes that. If an image is assigned the function will create the text link to search for and the new image link then it executes the swap. After it runs through every menu item it just returns the buffer which prints out to the browser. Pretty basic and you'll probably have to do some tweaking to get it just right for yourself but it's a nice way to use images without hacking any core files. Oh, and if you're just looking to use non web safe fonts then couple this method with a text-to-image conversion script and dynamically generate images from the menu item name. You could also use this with content headings or module headings or just about anything. Have fun.

Here's the callback function, put it above ob_start():

Download