Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Last active August 29, 2015 13:57
Show Gist options
  • Save jaredatch/9374389 to your computer and use it in GitHub Desktop.
Save jaredatch/9374389 to your computer and use it in GitHub Desktop.
Add description to WP menu output, avoids preg_replace
<?php
/**
* Add description to menu.
*
* Adjust description location as needed.
*
* @since 1.0.0
* @param string $item_output
* @param object $item
* @return string
*/
function ja_add_menu_description( $item_output, $item ) {
if ( !empty( $item->post_content ) ) {
$new_output = '<span class="description">' . $item->post_content . '</span>' . $item->title;
$item_output = str_replace( $item->title, $new_output, $item_output );
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'ja_add_menu_description', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment