Skip to content

Instantly share code, notes, and snippets.

@sachyya
Created January 29, 2017 07:03
Show Gist options
  • Save sachyya/7d7bf218eee152dba73a44f2d8691d6c to your computer and use it in GitHub Desktop.
Save sachyya/7d7bf218eee152dba73a44f2d8691d6c to your computer and use it in GitHub Desktop.
/**
<?php
* Descriptions on Header Menu
* @link https://codex.wordpress.org/Class_Reference/Walker
*
* @param string $item_output, HTML outputp for the menu item
* @param object $item, menu item object
* @param int $depth, depth in menu structure
* @param object $args, arguments passed to wp_nav_menu()
* @return string $item_output
*/
function sachyya_header_menu_item_desc( $item_output, $item, $depth, $args ) {
if( 'top' == $args->theme_location && ! $depth && $item->description )
$item_output = $item_output . '<span class="item-description">' . $item->description . '</span>';
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'sachyya_header_menu_item_desc', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment