Last active
August 29, 2015 13:57
-
-
Save jaredatch/9374389 to your computer and use it in GitHub Desktop.
Add description to WP menu output, avoids preg_replace
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 | |
/** | |
* 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