Snippets: Display Menu Descriptions in Main Menu

function be_header_menu_desc( $item_output, $item, $depth, $args ) {
	if ( 'main_menu' == $args->theme_location && ! $depth && $item->description ) {
		$item_output = str_replace( '</a>', '<span class="menu-item-desc">' . $item->description . '</span></a>', $item_output );
	}
	return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'be_header_menu_desc', 10, 4 );

Snippet Type: PHP

Posted Under: Menu

All PHP snippets should be added via a child theme's functions.php file.