Add ul ID in WordPress submenu
I want to add an ID to the submenu in WordPress that matches the link text
of the sibling like this:
<nav id="main-navigation" role="navigation">
<ul class="nav">
<li>
<a href="#about-us">About Us</a>
<ul id="about-us" class="sub-menu">
...
</ul>
</li>
</ul>
</nav>
I have a custom walker that looks like this:
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n" . $indent . '<ul id="' . $pleaseHelp . '"
class="sub-menu">' . "\n";
}
So my problem is; how to get the anchor link text as a variable and how to
make it URL friendly. (e.g. "About Us" -> "about-us")
And also, for the sibling a do something like this:
if ($subMenu){
<a href="$pleaseHelp">
}
Note: This is not for styling purposes but for accessibility and
usability, to be able to add aria-owns="about-us" and
aria-controls="about-us". (Ofc added w/ JavaScript)
No comments:
Post a Comment