Last active
May 8, 2019 16:13
-
-
Save anythinggraphic/ee250f60300a4d1a3278585ac2623602 to your computer and use it in GitHub Desktop.
Change the itemprop schema microdata attribute for navigation menu items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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