I would like, ideally in the php file of a menu override, to add role="menu-item"
i.e. direct links to another location, in a Joomla 3x (and 4x) menu.
Is this possible, or do I need to use JavaScript? (No jQuery, please).
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It only takes a minute to sign up.
Sign up to join this communityAfter much experimentation I'm pretty sure it's not possible to achieve this without Javascript, but I did manage it this way:
I added this code to the menu's main php file (about line 53 in the default.php override):
if ($item!=parent)
{
$class .= ' single';
}
Then in the template.js added this:
let single = [...document.querySelectorAll('li > a')];
[].forEach.call(single, function(sg) {
sg.setAttribute("role", "menuitem");
})
let singleb = [...document.querySelectorAll('li.single > button > a')];
[].forEach.call(singleb, function(sgb) {
sgb.setAttribute("role", "menuitem");
})
I'm using buttons in my navigation but if you're not you can leave out the second half of this code.