Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Thomas King
Thomas King
15,197 Points

Does Automattic give a reason for not using <nav> in their WordPress Menus?

I'm currently working on developing my first intensive WordPress theme, and I noticed that despite the new semantic <nav> tags being introduced, WordPress does not use them when you include menus in your theme's template files.

Has the core team given any explanation as to why these changes have not yet been adopted?

Could it be because it has run for so long with the <div class="menu"> syntax, that they are afraid everything will break and cascade down to sites not up-to-date?

Colin Marshall
Colin Marshall
32,861 Points

Are you referring to WordPress.com themes or the self-hosted WordPress.org?

Thomas King
Thomas King
15,197 Points

Colin Marshall - Referring to the WordPress.org installs. Even their latest version does not use 'nav' tagging for any of their menus.

1 Answer

Colin Marshall
Colin Marshall
32,861 Points

The presence of nav tags is dependent on the WordPress theme you are using, not on WordPress itself, however, WordPress does have a built-in function with an option to wrap a menu in nav tags.

The function wp_nav_menu will output an unordered list for a menu. This function has a $container option which can be set in the arguments if you want to wrap the unordered list in a set of tags. This option accepts either 'div' (default), 'nav', or false as a value.

I checked the last two official WordPress themes, Twenty Fifteen and Twenty Fourteen, and they both use nav tags. Those themes don't use the wp_nav_menu function to wrap their menus in nav tags, they just put the nav tags right in the template php. If you click the links for the themes above you will be taken to the theme file where the nav tags are present.

Does that clear it up for you at all? What themes are you looking at that do not use nav tags?

Thomas King
Thomas King
15,197 Points

My issue was the oddity of wp_nav_menu not adopting the nav tags into their function by 'default'.

It definitely clears up how I can include the type of tag I want in the argument of the function. I actually didn't notice that in the codex. (I suppose I better open my eyes!)

In your experience, have you had WP themes and the core not co-operate with each other when using HTML5 semantic tagging?

TwentyFourteen and TwentyFifteen being the obvious exceptions.

Colin Marshall
Colin Marshall
32,861 Points

This is just a guess, but if the default was originally to have div tags as the container, then they changed the default to nav tags it would probably break the CSS of a lot themes if they updated WordPress core. That would depend on if the themes used selectors in their CSS like div.menu, for example, because the theme's CSS would need to be changed to nav.menu to work properly.

Any time you change a default setting in widely used app like WordPress you have to be aware of how it will effect your users across the board.

As for my experience, I haven't really paid much attention to the semantics of WordPress themes unless it was a theme of my own. If the theme operated as advertised, I guess I wasn't really concerned about how the code behind the theme looked.