WordPress.org

Ready to get started?Download WordPress

Forums

wp_nav_menu: adding role="" to menu ul (3 posts)

  1. CAstijnen
    Member
    Posted 1 year ago #

    Hi,

    I am trying to add role="navigation" to the menu ul.

    Using wp_nav_menu you can only change the ID or the CLASS but you cannot add role="". I did some research and found out about the new walker function. I managed to add role="" to the sub menu's but not to the menu ul.

    simplified example:

    the basic output normally would be

    <ul id="menu-main">
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Blog</a></li>
    </ul>

    I want it to be

    <ul id="menu-main" role="navigation">
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Blog</a></li>
    </ul>

    Can you guys help me with this?! thanks!

  2. bcworkz
    Member
    Posted 1 year ago #

    You should be able to include the following parameter in the array argument passed to wp_nav_menu():

    'items_wrap' => '<ul id="%1$s" class="%2$s" role="navigation" >%3$s</ul>'

  3. CAstijnen
    Member
    Posted 1 year ago #

    That worked flawless, thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic