Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add descriptions to navigation items
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add description to menu items
add_filter( 'walker_nav_menu_start_el', 'wpstudio_add_description', 10, 2 );
function wpstudio_add_description( $item_output, $item ) {
$description = $item->post_content;
if (' ' !== $description ) {
return preg_replace( '/(<a.*)</', '$1' . '<span class="menu-description">' . $description . '</span><', $item_output) ;
}
else {
return $item_output;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment