Last active
January 30, 2024 21:24
-
-
Save frankschrijvers/2ef89b73731d148fd853 to your computer and use it in GitHub Desktop.
Add descriptions to navigation items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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