Recently I read an awesome post by Bill Erickson about customizing WordPress menus. However, there are two things I wanted this class to do that in its original form it doesn’t do.
So since out of the box, WordPress doesn’t intuitively allow you to add descriptions to the menu without requiring some custom code, rather the Walker class extended.
Since Bill has done an excellent job at this I will extend his code to add the options of having a featured image and/or descriptions applied based on depth.
Add this to your functions.php file.
To highjack ALL of your menus, enter this code in your functions.php.
Menus Based on Location
To highjack a menu based on registered and assigned location, then use this code in your functions.php.
Menus via WordPress Custom Menu Widget
To highjack a custom menu based menu id that is called using the custom menu widget, or even a manual method (if the menu is being called by a location, you must use ‘theme_location’), then use this code in your functions.php. This will highjack any menu called by the custom menu widget assuming you only have the standard registered theme locations. The example below assumes a standard theme custom menu registered locations for Genesis. Change ‘primary’ and/or ‘secondary’ to whatever your theme adds and add whatever more menus that your theme has to only target the custom menu widget.
There is a caveat though. There are certain menu items that may not have a featured image such as custom links, categories, etc. There is a possible work-around that I am trying to work out.
Here is the result of a sandbox description and featured images for all types (not just pages and posts), which I will be posting soon or writing up into a plugin…