I would like to add the schema.org SiteNavigationElement and the relative url property to the links of the navbar.

I have the following:

<nav class="navbar navbar-default navbar-fixed-top" id="menu-nav" role="navigation">
  <!-- Brand and toggle get grouped for better mobile display -->
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
  <!-- Collect the nav links, forms, and other content for toggling -->
    <?php wp_nav_menu( array(
      'sort_column'     => 'menu_order',
      'theme_location'  => 'header-menu',
      'items_wrap'      => '<ul class="menu-nav navbar-nav scroll-menu">%3$s</ul>',
      'container_class' => 'collapse navbar-collapse menu-header '
    ) ); ?>

I understand that itemscope itemtype="http://schema.org/SiteNavigationElement" should go to the <nav>. That's fine, and I can do that.

However how can I add itemprop="url" to the links of that navbar??


1 Answer 1


A little searching got me the nav_menu_link_attributes filter:

function wpse183311_filter( $atts, $item, $args ) {
    $atts['itemtype'] = 'http://schema.org/SiteNavigationElement';
    return $atts;
add_filter('nav_menu_link_attributes', 'wpse183311_filter', 3, 10);

Add however many attributes you need to the $atts array as necessary

  • Hi, I think this is not what I need. Because I can add itemscope itemtype="http://schema.org/SiteNavigationElement" directly in the code below editing just the HTML. The problem, as I wrote above, is to add itemprop="url" to every URL of the navbar. These are wordpress menu functions, and this code is not in the theme.
    – Pikk
    Commented Apr 5, 2015 at 16:34
  • That's exactly what this code does.. If you look at the code it shows you the method for adding any attribute you want to the links in a nav menu..
    – Tom J Nowell
    Commented Apr 5, 2015 at 16:35
  • This answer does assume a knowledge of basic PHP and basic WordPress filters, was I wrong in that assumption? Or were you looking for a lazy copy paste step by step instructions for non-developers
    – Tom J Nowell
    Commented Apr 5, 2015 at 16:37
  • Well, I wanted the lazy version :) But I understood it and it works fine. Thanks.
    – Pikk
    Commented Apr 5, 2015 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.