Edit: after doing some research I've found that in the wp_nav_menu
function uses the following code to display the containers value.
if ( $args->container ) {
/**
* Filter the list of HTML tags that are valid for use as menu containers.
*
* @since 3.0.0
*
* @param array $tags The acceptable HTML tags for use as menu containers.
* Default is array containing 'div' and 'nav'.
*/
$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags ) ) {
$show_container = true;
$class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"';
$id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
$nav_menu .= '<'. $args->container . $id . $class . '>';
}
}
lines 341 to 357 https://developer.wordpress.org/reference/functions/wp_nav_menu/
$nav_menu .= '<'. $args->container . $id . $class . '>';
The above line deals with the output of the container information I'm now trying to figure out how to modify this information within the custom walker class to add the extra fields.
End of Edit
I'm currently trying to add aria roles and schema markup to a custom walker I've created.
I'm trying to avoid wrapping the menu inside the tags directly like below. I would prefer to edit the container and attach the extra elements dynamically.
<nav class="" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
wp_nav_menu( $defaults );
</nav>
Currently my wp_nav_menu call looks like this.
$defaults = array(
'menu' => '',
'menu_class' => '',
'menu_id' => '',
'container' => 'nav',
'container_class' => 'a-primarymenu',
'container_id' => '',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 0,
'walker' => new Custom_Nav_Walker( 'a-primarymenu' ),
'theme_location' => 'primary',
'items_wrap' => '<ul>%3$s</ul>',
); wp_nav_menu( $defaults );
The container class I assign is passed to the custom walker class and allows my menu output to be as follows.
<nav class="a-primarymenu">
<ul>
<li class="a-primarymenu__item"><a href="#link">Link</a></li>
<li class="a-primarymenu__item"><a href="#link">Link</a></li>
<li class="a-primarymenu__item"><a href="#link">Link</a></li>
<li class="a-primarymenu__item"><a href="#link">Link</a></li>
<li class="a-primarymenu__item"><a href="#link">Link</a></li>
</ul>
</nav>
What I need help with is figuring out how to modifer the container html output
aka <nav class="a-primarymenu">
so I can add role="navigation"
and itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement"
to the element.
Which would then produce.
<nav class="a-primarymenu" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
The closest match I could find to this desired output was https://core.trac.wordpress.org/ticket/35127 however this is just a request to the wordpress core and not a modifiered walker.
container
=>false
and wrapul
list inside yournav
element.