Skip to content

Instantly share code, notes, and snippets.

@cheh
Forked from billerickson/gist:1325518
Created March 11, 2014 20:55
Show Gist options
  • Save cheh/9494869 to your computer and use it in GitHub Desktop.
Save cheh/9494869 to your computer and use it in GitHub Desktop.
<?php
/**
* Add description to menu
* @author Bill Erickson
* @link http://www.billerickson.net/code/add-description-to-menu
*
* @param string $item_output
* @param object $item
* @return string modified item output
*/
function be_add_description( $item_output, $item ) {
$description = $item->post_content;
if (' ' !== $description )
return preg_replace( '/(<a.*?>[^<]*?)</', '$1' . '<span>' . $description . '</span><', $item_output);
else
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'be_add_description', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment