Function - WpScriptly

Enhance Your WordPress Navigation with the Menu Title Attribute Script

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;
}

Notes:

Wp Scriptly

These scripts, CSS styles, and plugins are designed to work best with minimal interference from themes or other plugins. If conflicts arise, adjustments may be needed.
Please note that they must be used as is.”

Let me know if you’d like any further refinements!

Wp Scriptly

Was this information helpful?

One Comment