Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add category ID to 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.