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()
?
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
alt
is for images, not for<a>
. – alexwc_ Commented Nov 30, 2019 at 22:11