Skip to content

Instantly share code, notes, and snippets.

@anythinggraphic
Last active May 8, 2019 16:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anythinggraphic/ee250f60300a4d1a3278585ac2623602 to your computer and use it in GitHub Desktop.
Save anythinggraphic/ee250f60300a4d1a3278585ac2623602 to your computer and use it in GitHub Desktop.
Change the itemprop schema microdata attribute for navigation menu items
<?php
/* @link https://anythinggraphic.net/change-navigation-menu-item-url-itemtype-schema-microdata/
/* Change microdata for specific menu items
----------------------------------------------------------------------------------------*/
add_filter( 'nav_menu_link_attributes', 'ag_menu_item_attributes', 10, 3 );
function ag_menu_item_attributes( $atts, $item, $args ) {
// The ID of the target menu item
// Remove this to target all menu items
$menu_target = 123;
// Remove if statement to target all menu items
if ($item->ID == $menu_target) {
// Since this is a mailto: link, we need it to be blank
$atts['itemprop'] = 'URL or EMAIL or SOMETHING'; //schema.org
}
return $atts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment