Enhance Your WordPress Navigation with the Menu Title Attribute Script

By Webmaster

Posted: 12m & 27d ago
🕑 1 min read

👁 Views: 359

(1) Leave a Comment

Function - WpScriptly

Introducing the “Menu Title Attribute” WordPress script! This script enhances your website’s navigation by automatically applying the navigation label to the title attribute of each menu item. This ensures better accessibility and provides additional context to users when they hover over menu links. The script is easy to install and activate, requiring no additional configuration. By improving the user experience, “Menu Title Attribute” helps your website be more user-friendly and SEO-friendly.

This script works with kadence, Astra and all wordpress themes.

I use fluent snippet plugin for all my functions, js, and CSS:

Place this script in your favorite code snippet plugin and give it a name. Once you do that click save that all you have to do. If you have a caching plugin clear cache and hover over a item in the menu now.

add_filter('wp_nav_menu_objects', 'add_nav_label_to_title_attribute');

function add_nav_label_to_title_attribute($items) {
    foreach ($items as $item) {
        if (!empty($item->title)) {
            $item->attr_title = $item->title;
        }
    }
    return $items;
}
Author: Webmaster, Admin at WpScriptly

Hey, I’m Scot, the guy behind WpScriptly. I create simple, no-fluff WordPress plugins and tools to make your site easier to manage and more powerful. Everything I build is tested on my own projects first — if it’s here, it’s because it works. Thanks for checking out the site. Hope you find something useful at Wp Scriptly.

*These scripts and plugins are provided as is with no guarantees or warranties. If you need assistance or run into issues, feel free to reach out via the contact page.

One Comment