Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #615637

    dasickle
    Participant

    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?

    #615638

    dasickle
    Participant
    This reply has been marked as private.
    #615942

    Lely
    Moderator

    Hello There,

    Thanks for posting in.
    Please check this thread:https://community.theme.co/forums/topic/schema-markup/

    Hope this helps.

    #616583

    dasickle
    Participant

    I 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.

    #616784

    Nabeel A
    Moderator

    Hi 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!

    #616961

    dasickle
    Participant

    Crawlers 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.

    #617089

    Zeshan
    Member

    Hi 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!