php - How do I modify the <li> <a> <a> <li> with wp_nav_menu()

admin2025-04-18  0

I try to add an "alt=" attribute to the <a> of the menu in WordPress but I don't see the form, look in the whole template and I can't find information other than wp_nav_menu()

<?php
    wp_nav_menu(
        array(
            'theme_location' => 'primary',
            'container'      => false,
            'fallback_cb'    => 'orbital_default_menu',
            'items_wrap'     => '<ul>%3$s</ul>',
        )
    );
?>

What I can hardly understand is that the <ul>%3$s</ul> variable generates <li> <a> </a> </li>

Any way to modify the <a> </a> using wp_nav_menu()?

I try to add an "alt=" attribute to the <a> of the menu in WordPress but I don't see the form, look in the whole template and I can't find information other than wp_nav_menu()

<?php
    wp_nav_menu(
        array(
            'theme_location' => 'primary',
            'container'      => false,
            'fallback_cb'    => 'orbital_default_menu',
            'items_wrap'     => '<ul>%3$s</ul>',
        )
    );
?>

What I can hardly understand is that the <ul>%3$s</ul> variable generates <li> <a> </a> </li>

Any way to modify the <a> </a> using wp_nav_menu()?

Share Improve this question edited Dec 1, 2019 at 7:47 nyedidikeke 4921 gold badge6 silver badges15 bronze badges asked Nov 30, 2019 at 17:04 Plantas y remedios CaserosPlantas y remedios Caseros 33 bronze badges 1
  • I believe alt is for images, not for <a>. – alexwc_ Commented Nov 30, 2019 at 22:11
Add a comment  | 

1 Answer 1

Reset to default -1

Welcome to WPSO. You need to modify the Walker_Nav_Menu Class. That class is responsible for rendering the HTML menu output in first place. The theme you are using is calling the WordPress menu class, which will then output your menu.

As alexwc_ mentioned the alt attribute is for images, not for anchor tags.

So in order to maniputelate the menu output, you need to implement your own "walker".

See:

Custom Nav Walker Tutorial

YouTube Video

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744951521a276364.html

最新回复(0)