You may target the current_page_item
CSS class or you may target the current-menu-item
CSS class instead. current_page_item
class may not be present for all kinds of menu item. Read the answer here to know why.
Whichever CSS class you choose, you may use the CODE like the following to set the attribute:
add_filter( 'nav_menu_link_attributes', 'wpse260933_menu_atts_filter', 10, 3 );
function wpse260933_menu_atts_filter( $atts, $item, $args ) {
if( in_array( 'current-menu-item', $item->classes ) ) {
$atts['aria-current'] = 'page';
}
return $atts;
}
Related Posts:
- Accesibility problems with dropdown menus in twentyten theme or others
- How to change the wordpress navigation bar UL to OL in Twenty_Twelve similer theme
- SlickNav – Google Lighthouse Accessibility issue for collapsed menu button
- What are some of your favorite methods for creating an accessible menu?
- Split up wp_nav_menu with custom walker
- how to create a menu with all sub categories?
- How to avoid wp_nav_menu() ID conflict?
- WordPress Menu Custom Walker Class
- How to change order of menu items
- Remove unusable metaboxes in nav menu management screen
- Highlight parent menu item when child is not in menu
- Add Commas Between Menu Items?
- Allow html tags in WordPress Custom Menus Description Field
- How to custom output wp_nav_menu()
- Determine if a navigation item has children
- Directing a page to a default subpage
- How to register custom menu widget
- Menu items id’s – are they 100% unique?
- Links open only on new tab or window
- Show different different menu in theme_location depending on x
- How to Create a Custom WordPress Navigation Menu with the Code?
- How to add ID and class in nav menu walker?
- Set Item Order with wp_nav_menu_{$menu->slug}_items
- How can I get an array/list of all current WordPress Admin Menu items?
- Add “parent” class to parent menu items
- Add class to active element and its parent in nav menu
- Handling complex multi-level architecture / menu for large site
- Menu styling for last menu item
- WP Nav menu append to url
- Must a page be published in order to be added to menu?
- Hiding Admin Page While Keeping Menu Expanded
- How to add a tag to wp_nav_menu in a child theme
- Third level navigation class
- How to add a submenu toggle button inside all “li” elements that have a submenu?
- Best way to customise wp_nav_menu [duplicate]
- is_page() not working with archives?
- How to Overwrite/Customize wp-admin/nav-menus.php in WordPress
- Filter for Admin Nav Menus Drop Down
- How do you manage large menu hierarchies in WP?
- wp_list_pages() but only show children on the branch you are on
- Tidy nav menu classes except for edit-menu-item-classes and active class
- I need help adding a second custom menu item to the WooCommerce account area menu
- Cant add menu items with my theme
- Why aren’t my post showing under my custom menu?
- Dynamically add sub menu items
- Custom Menu’s – Disable Link checkbox
- Using my WordPress menu on another platform
- Header and nav menu problem on Thesis site [closed]
- How to style a specific nav menu item?
- remove class “sub-menu” from wordpress drop down menu
- Add a submenu to wp_nav_menu
- Twenty seventeen Menu is not responsive not clickble
- remove menu items if user can’t read
- How to set classname for tag in wordpress menu?
- Automatically going to the first page in a hierarchy?
- Is there a hook for nav menu item links to add custom css programatically?
- rearrange the posts by published date in Menu posts selection
- Setting color of specific menu items depending on page or post tag
- sub menu link is not working
- wp_get_archives doesn’t take effect from css or html
- Orderby menu_order not working; menu is sorted on publish date
- Change Menu Button Text [closed]
- Show Sidebar Menu Subpages When Clicking Parent
- Menu page with three columns
- Appearance > Menus > Left Sidebar > Add Toggle
- How to open a lightbox form from a navigation menu item
- Efficient wp mobile menu
- Echo Menu located in primary navigation
- Auto delete menu items with zero products (woocommerce)
- Admin menu in different languages
- Navigation item – current date in url
- Need help with Walker_Nav_Menu class
- Impossible to remove page from menu
- why are my walker menu is showing like this?
- Bootstrap Theme Migrated to WordPress
- How to remove top menu item and font awesome icon in WordPress menu?
- Menu with sub-items but without link
- Creating navigation out of specific IDs and their children?
- I can´t make the menu unclickable in an easy way
- 2nd level (drop-down) of the navigation menu not working [closed]
- Add active class to wp_nav_menu
- how to configure this type of menu
- Migrate WP Menu between sites
- show a hidden ul if li is active
- How can I make menu items into two seperate buttons with different functions?
- How to style wp_nav_menu?
- How to inject HTML to secondary menu on front end?
- Different colors for navigation bar
- Eliminate menu collapse button on website
- Show Child of Parent Page including all other parents
- wp_nav_menu in 3.7 add name class nav navbar-nav
- WordPress Navigation default output
- Specifying Class style for Menu
- Is there a limit to number of pages displayed for selection in custom menu?
- Convert HTML code to WordPress menu
- How to view menu and submenus in URL
- Add monthly archives menu and submenu
- wp nav menu – highlighting current page not working properly [closed]
- Hamburger Navigation Menu
- Database structure Menu Item