Enhance Your WordPress Navigation with the Menu Title Attribute Script

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

Notes:

Wp Scriptly

This basic script, CSS style, and plugin are designed to function optimally assuming minimal interference from your theme or other plugins. If conflicts occur or further customization is needed, additional adjustments may be necessary. Please note that this script, CSS style, or plugin must be used AS IS.

Wp Scriptly

The WpScriptly Monthly newsletter offers top insights for WordPress pros: new scripts, plugins, resources, tips, tools, updates, and more every month.

Sidebar Subscribe

One Comment