Add additional text to the WordPress menu title attribute

WordPress comment three hundred and sixty-nine Reading mode

The menu title attribute is the prompt text when the mouse hovers over the menu title. The following code can add additional text and links to the menu title attribute.

 Add additional text to the WordPress menu title attribute

Add additional text to the WordPress menu title attribute

Add code to the current topic function template functions.php:

 //Add additional text to the menu title attribute add_filter( 'walker_nav_menu_start_el', 'zm_nav_menu_item', 20, 4 ); function zm_nav_menu_item( $item_output, $item, $depth, $args ) { $extra_title='Additional text'; if (strpos( $item_output, 'title=' ) ) { //If the title attribute has been added, attach $extra_title to the existing menu title attribute. return preg_replace( '/title=\"([^\"]*)\"/', 'title="\1 - '.$ extra_title.' "', $item_output, 1 ); } else { //If the title attribute is not added, add the menu title attribute consisting of the menu title and $extra_title. return str_replace( 'href=', 'title="'.$item->title.' - '. $extra_title.'" href=', $item_output ); } }

 

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 anonymous

Comment

Anonymous netizens
 :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

Drag the slider to complete validation