Feb 5, 2013

Add Class to Specific Link in Custom Menu


SOLVED!!!! I needed to figure this out to make the menu item link to inline HTML in a fancybox. Paste the following code into your theme's function.php:
function add_menuclass($ulclass) {
    return preg_replace('/, ', $ulclass, -1);
}
add_filter('wp_nav_menu','add_menuclass');
Then... in the Menu tab of the WP Dashboard, create a custom link, add it to your menu. On the top where is says Screen Options, make sure you have "Link Relationship (XFN)" checked. It will add that field to your custom menu item. Type "fancybox" (without quotes) into the field and save your menu.
The function looks for the call to the navigation menu, then finds wherever you have arel="fancybox" and replaces it with a rel="fancybox" class="fancybox". You can replace fancybox with whatever class you need to add to your menu items. Done and done!

No comments: