-
-
Save billerickson/1cc2c10068f203e6f1d4 to your computer and use it in GitHub Desktop.
Descriptions on Header Menu
This file contains hidden or 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 | |
/** | |
* Descriptions on Header Menu | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/code/add-description-to-wordpress-menu-items/ | |
* | |
* @param string $item_output, HTML outputp for the menu item | |
* @param object $item, menu item object | |
* @param int $depth, depth in menu structure | |
* @param object $args, arguments passed to wp_nav_menu() | |
* @return string $item_output | |
*/ | |
function be_header_menu_desc( $item_output, $item, $depth, $args ) { | |
if( 'header' == $args->theme_location && ! $depth && $item->description ) | |
$item_output = str_replace( '</a>', '<span class="description">' . $item->description . '</span></a>', $item_output ); | |
return $item_output; | |
} | |
add_filter( 'walker_nav_menu_start_el', 'be_header_menu_desc', 10, 4 ); |
Hello,
Is there a way to make this work with putting the description in front of the <a href>
?
@oneblackcrayon, yes
$item_output .= "<span>$item->description</span>";
and add styles to span.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@param string $item_output, HTML outputp for the menu item
clerical mistakeoutputp
.I adjusted the function a little bit: