Category ID on Menu Items

<?php
/**
* Category ID on Menu
*
* @author Bill Erickson
* @link http://www.billerickson.net/code/category-id-on-menu-items
*
* @param array $classes
* @param object $item
* @return array $classes
*/
function be_category_id_on_menu( $classes, $item ) {
if( $item->object !== 'category' )
return $classes;
$classes[] = 'menu-item-category-' . $item->object_id;
return $classes;
}
add_filter( 'nav_menu_css_class', 'be_category_id_on_menu', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

menu

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk