-
AuthorPosts
-
October 7, 2015 at 3:57 pm #615637
I am trying to add the following markup to my menu items:
<ul itemscope itemtype="http://www.schema.org/SiteNavigationElement"> <li itemprop="name"><a href="http://www.domain.com">Links</a></li> </ul>
How can see be accomplished in my child theme? Which framework file or function do I need to edit?
October 7, 2015 at 3:58 pm #615638This reply has been marked as private.October 7, 2015 at 9:33 pm #615942Hello There,
Thanks for posting in.
Please check this thread:https://community.theme.co/forums/topic/schema-markup/Hope this helps.
October 8, 2015 at 8:24 am #616583I am fully aware of how to work with the child themes and edit the files. However, to add this markup to the menu I think I will need to edit the function that generates the main menu. I have looked everywhere for it and cant find it.
October 8, 2015 at 10:48 am #616784Hi again,
You can try adding the following jQuery script in your Customizer via Appearance > Customize > Custom > Javascript
jQuery(document).ready(function($){ $('.x-nav').attr({itemtype:'http://www.schema.org/SiteNavigationElement', itemscope:''}); $('.x-nav li').each(function(){ $(this).attr("itemprop", "name"); }); });
Don’t forget to clear your browser’s cache after adding the code. Let us know how this goes!
October 8, 2015 at 12:52 pm #616961Crawlers will not read the jQuery inserted metadata. I need to add this content prior to sending the http response. A post-render JavaScript solution is insufficient because the metadata is invisible to search engines.
That being said, I need to modify the function that creates the primary nav. Could you please let me know which function I need to edit.
October 8, 2015 at 2:21 pm #617089Hi there,
This function is outputting the primary navigation and can be found in file wp-content/themes/x/framework/functions/global/navbar.php:
// Output Primary Navigation // ============================================================================= if ( ! function_exists( 'x_output_primary_navigation' ) ) : function x_output_primary_navigation() { if ( x_is_one_page_navigation() ) { wp_nav_menu( array( 'menu' => x_get_one_page_navigation_menu(), 'theme_location' => 'primary', 'container' => false, 'menu_class' => 'x-nav x-nav-scrollspy', 'link_before' => '<span>', 'link_after' => '</span>' ) ); } elseif ( has_nav_menu( 'primary' ) ) { wp_nav_menu( array( 'theme_location' => 'primary', 'container' => false, 'menu_class' => 'x-nav', 'link_before' => '<span>', 'link_after' => '</span>' ) ); } else { echo '<ul class="x-nav"><li><a href="' . home_url( '/' ) . 'wp-admin/nav-menus.php">Assign a Menu</a></li></ul>'; } } endif;
You can copy the exact same function in your child theme’s functions.php file, and make your make the changes as per your preference.
Hope this helps. 🙂
Thank you!
-
AuthorPosts