Structured Data (Schema.org)

Knowledgebase Docs » UberMenu 3
USEFUL? 2
UberMenu 3

Current Status

As of WordPress 4.4, the wp_nav_menu() function does not have the ability to add the necessary attributes to use structured data.

Trac Ticket

On December 16, 2015, I submitted a ticket with suggested core code changes for the wp_nav_menu() function, which will allow arbitrary attributes to be set on the menu container, enabling the use of structured data in WordPress menus. Hopefully this suggestion will be incorporated into core at some point in the future.

You can review the ticket here

Future Plans

If and when this code is adopted into the core, new settings will be added to UberMenu to enable the Schema.org structured data attributes automatically.

Interim Solution

If you would like to add these attributes to UberMenu in the meantime, you can drop this filter into your functions.php. It will only affect UberMenus, and only those with the Container Tag set to nav

function um_schema_filter( $nav_menu , $args ){
   if( isset( $args->uber_integration_type ) ){
      $nav_menu = str_replace( '<nav ' , '<nav role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement" ' , $nav_menu );
   }
   return $nav_menu;
}
add_filter( 'wp_nav_menu' , 'um_schema_filter' , 20 , 2 );

Be careful, string replacement can be unreliable if other themes/plugins are also manipulating the menu output. If this does not have the desired effect, just remove it from your functions.php.