最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览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

发布评论

评论列表(0)

  1. 暂无评论