Created
April 21, 2020 04:38
-
-
Save cesgarma/2e2821fa0f22a77466909d5aa2907c74 to your computer and use it in GitHub Desktop.
https://elizabethfreemanweb.com/how-to-add-google-structured-data-to-wordpress-menus/ Wanted result in HTML <span itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement"> <ul id="menu-main" class="nav"> <li class="menu-main"
This file contains hidden or 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 | |
/* Add the following to the Theme header.php (typically) */ | |
<nav itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement" role="navigation"> | |
wp_nav_menu(['theme_location' => 'primary_navigation', 'walker' => MyNavWalker(), 'menu_class' => 'nav']); | |
</nav | |
/* Add this to the functions.php . This adds the 'url' attribute to every <a> link in the menu */ | |
function add_menu_attributes( $atts, $item, $args ) { | |
$atts['itemprop'] = 'url'; | |
return $atts; | |
} | |
add_filter( 'nav_menu_link_attributes', 'add_menu_attributes', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment