HTML Title Attribut zu WordPress Navigation Links hinzufügen

PHP
<?php 

add_filter('walker_nav_menu_start_el', 'add_title_attribute_to_menu', 10, 4);

function add_title_attribute_to_menu($item_output, $item, $depth, $args) {
    // Check if this is the primary menu
    if ($args->theme_location === 'primary') {
        // Add the title attribute to the <a> tag
        $title = esc_attr($item->title); // Escape for safety
        $item_output = preg_replace('/<a /', '<a title="' . $title . '" ', $item_output, 1);
    }

    return $item_output;
}