How to modify attributes of any wordpress menu item link
Recently while working on one of the project, I needed to remove the title attribute of WordPress generated menu item.
It was a child theme and menu was already generated by the parent theme.
So to fix this issue, I had to write a small filter to remove the generated code. To remove the title attribute from WordPress menu item, we can use “nav_menu_link_attributes” filter.
“nav_menu_link_attributes” filters the HTML attributes applied to a menu item’s anchor element.
Are you facing “jQuery Is Not Defined WordPress” Issue?
Check how to fix wordpress jquery is not defined issue.
This filter runs per nav item. This is used to add, modify or delete HTML attributes of WordPress menus nav item, generated with the WP Menu API.
Here is the WordPress filter to remove/modify link title attribute of menu nav item.
add_filter( 'nav_menu_link_attributes', 'remove_title_from_menu', 10, 4 );
function remove_title_from_menu( $atts, $item, $args, $depth ){
unset($atts['title']);
return $atts;
}
Similarly, say if you want to add a custom HTML attribute or if you want to add HTML Data attributes to links, then you can use the same filter.
Here is a sample code to do the same
add_filter( 'nav_menu_link_attributes', 'add_data_attribute_menu', 10, 4 );
function add_data_attribute_menu( $atts, $item, $args, $depth ){
$atts['data-info'] = 'Custom '.$atts['title'].' information';
return $atts;
}
Also, if you want to add custom text for all links which are opening in new tab eg. external link. Then you can use this function to add custom class to WordPress navigation menu item.
If you want to know more about this filter, then here is a link to nav_menu_link_attributes documentation.
Is it useful? Don’t forget to share it with your friends & colleagues.
Did you use this WordPress filter? What was your use case? Let me know in comments.
GPT 5.4: The Next-Generation AI Model Transforming Reasoning, Coding, and Productivity Artificial Intelligence is evolving…
GPT-5.3 Instant is OpenAI's latest ChatGPT model update, prioritizing smoother conversations, fewer refusals, and higher…
Are you tired of scrolling endlessly through Google results trying to find clear, trustworthy answers?…
In recent years, the process of software development has rapidly evolved—developers demand smarter tools and…
India has emerged as one of the fastest-growing and most significant markets in the global…
On October 6, 2025, OpenAI unveiled AgentKit, a unified suite of tools designed to help developers and…
This website uses cookies.