Skip to content

Instantly share code, notes, and snippets.

@michaelcarwile
Last active December 22, 2015 04:48
Show Gist options
  • Save michaelcarwile/6419381 to your computer and use it in GitHub Desktop.
Save michaelcarwile/6419381 to your computer and use it in GitHub Desktop.
Output/display WordPress nav descriptions on Genesis Theme
<?php
// don't copy php tag
/* Inspired by:
http://www.wpstuffs.com/add-menu-description-in-genesis/
http://www.billerickson.net/genesis-quick-tips/
*/
//* Display nav descriptions (div after text within anchor - <a href>"Menu Name"<div>"Description"</div></a>)
function add_description_nav( $item_output, $item ) {
$description = $item->post_content;
return preg_replace( '/(<a.*?>[^<]*?)</', '$1' . '<div>' . $description . '</div><', $item_output);
}
add_filter( 'walker_nav_menu_start_el', 'add_description_nav', 10, 2 );
// * SECOND OPTION - ONLY CHOOSE ABOVE OR BELOW CODE
//* Display nav descriptions (div before anchor - <div>"Description"</div><a href>"Menu Name"</a>)
function add_description_nav( $item_output, $item ) {
$description = $item->post_content;
return preg_replace( '/(<a.*?>)/', '$1<div></div>', $item_output);
}
add_filter( 'walker_nav_menu_start_el', 'add_description_nav', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment