Skip to content

Instantly share code, notes, and snippets.

@frankschrijvers
Last active January 30, 2024 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frankschrijvers/2ef89b73731d148fd853 to your computer and use it in GitHub Desktop.
Save frankschrijvers/2ef89b73731d148fd853 to your computer and use it in GitHub Desktop.
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