• I am new to wordpress theme development.

    <nav class="site-nav">
            <?php 
                        $args = array(
                        'theme_location' => 'primary'
                        );
                    ?>
                    <?php wp_nav_menu( $args); ?>
                </nav>

    But in html it is showing an extra a tag

    <ul id="menu-primary-menu-links" class="menu"><a href="https://localhost/learn"></a><li id="menu-item-19" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-19"><strong><a href="https://localhost/learn"></a></strong><a href="https://localhost/learn/portfolio/">Portfolio</a></li>
    <li id="menu-item-18" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-6 current_page_item menu-item-18"><a href="https://localhost/learn/about-us/" aria-current="page">About Us</a></li>
    <li id="menu-item-20" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20"><a href="https://localhost/learn/contact-us/">Contact Us</a></li>
    </ul>

    what I am missing. In my menu configuration I have added only 3 pages. so I am not expecting this extra a element.

    • This topic was modified 4 years, 9 months ago by gyan1990ex.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The extra tags are inserted by either your theme or a plugin. The WP core menu scheme only utilizes elements seen on the menu edit screen, no “special” extras are inserted by default. However, the WP menu scheme provides several filters in which a theme or plugin can insert additional content.

    If the added elements are not impacting your site’s appearance or functionality, it may not be worth the effort to remove them. But if you want or need to do so, identify which module is the cause by selectively switching themes or deactivating plugins until the undesired HTML disappears.

    You could then ask through that module’s dedicated support channel if there’s a setting or some reasonable way to remove the extra content. If that doesn’t prove fruitful, it’s possible to add some custom code to remove it. Ideally, find the code which adds the filter hook responsible for the addition. This is done with a call to add_filter(). You can then call remove_filter() from your own code, but it must be done after the addition is performed.

    If all else fails, the filter “wp_nav_menu” can be used to find the offending HTML within the menu’s full HTML and removed with str_replace().

Viewing 1 replies (of 1 total)
  • The topic ‘Getting extra a tag in first element of wp_nav_menu li’ is closed to new replies.