The below filter adds your class based on title, you could also do this by post ID if you’d like: $item->object_id == 123
function wp_nav_parent_class( $classes, $item ) {
if( is_singular('post') && $item->title == "Your Menu Item Title Here" )
array_push($classes, 'current_page_parent');
return $classes;
}
add_filter('nav_menu_css_class', 'wp_nav_parent_class', 10, 2);
If is_singular('post')
does not work try is_single()
, but it should work. Just replace the conditional string with the menu item title of your choice.
Related Posts:
- Why do Custom Nav Menus generate so many classes on list items? Can I manage this somehow?
- Custom search filter causes menu and query_posts problems
- Add separator to admin submenu
- register_nav_menus() won’t register menus
- How do I add nested categories to drop-down menu in twenty-eleven?
- Add custom page link with anchor
- How to include the ‘current-menu-ancestor’ class on a custom post type menu in WordPress?
- How to add menu to Dashboard that can be viewed by all users
- List children of second level sub page
- Show top-level parent with submenu menu walker
- Add section to custom menu panel
- Adding a class (arrows) to main menu links that have children?
- How to change menu according to the language?
- Adding menu items dynamically using wp_nav_menu_objects
- Highlight the “Home” / “Blog” button while on main page
- Navigation (wp_nav_menu) refuses to nest within parent element
- how to add Custom menu item like User name in Header Menu only
- Display three different levels of navigation from wp_nav_menu separately?
- Wp_Nav_Menu – Identify the last menu item
- Add custom menu item metabox in Navigation Settings
- Menus – Open items in new tab/window?
- Image as a link using wp_nav_menu()
- Highlight another nav item
- Custom Menu url is Empty
- Get category ID from nav menu
- How to make link to different categories that in them selves loads different menus?
- Menus don’t appear in admin area / WordPress Multisite
- Programmatically add existing pages and subpages to Appearance Menu
- Highlight current post ancestor parent menu items
- Ad custom admin page like WordPress customizer [closed]
- Appearance Menus Screen – menu item drop down menu not functioning
- Weird behaviour on Edit Menus screen
- Remove nav menu item by script
- Make a navigation menu in the same post [duplicate]
- Custom Menu Broken WP 3.8.1 Update
- How to actually make menu walker alive on admin interface?
- Get menus created with menu editor?
- How to I know the class or ID of my theme?
- Highlight parent if item from submenu is active
- How to exclude pages in the menu without pageID?
- Missunderstanding of WordPress menus
- changing host.. data loss
- Theme Location empty
- Replace the slug of parent pages with # [closed]
- How to buid wordpress menu with auto width sub-menu items in dropdown menu without any items sharing one line [closed]
- Wrapping menu’s top-level link and sub-menus in div
- Page appears after de registering from menu
- Menu on mobile version doesn’t collapse after choosing menu item [closed]
- If current menu item is child or parent with child?
- Is it possible to dynamically register menus?
- Dynamic menu wp_list_pages displaying only current branch including: current page, his siblings and its childs
- WordPress Menu Exchange for Mobile Layout
- Question about Menus on WordPress
- Switching to child theme breaks menu names
- Bootstrap menu – make menu entries with submenu not clickable
- How to implement a secondary menu?
- Styling issue with custom menus and sub menus
- When I click a custom menu link, how do I make it update the URL in the browser to the external link?
- Disabling tooltip on menu items
- Divide Menu into Separate Menus and Display them Side by Side
- Using menus to link to sections on the home page
- Hook or callback when wp_nav_menu() has completed
- if role is logged in then do something
- Set one or more menus as a submenus of another menu
- How to show submenu of any page in main menu
- How to change the navigation menu
- Menu links URL with PHP GET method
- WordPress nav_menu items from another menu appearing
- Adding widget to sidebar which contains current page’s submenu
- WordPress theme editor not showing
- How to switch menu location in this header.php?
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Extending Walker_Nav_Menu in wp_nav_menu List of Empty Items
- Jump to section on another page from menu item
- Users are required to login to my site. How define user.member boolean, its permissions, and conditionally display/handle behavior based on it
- How to Use Default Auto-Generated Menu?
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- Two questions about CSSing inside the menus
- Different menu on different category need advice
- Add items to a menu
- Is there any way to recover deleted menu from database sql backup
- Use menu structure for permalinks
- Add tooltips with image in WordPress Menu?
- How to make a drop down menu with categories
- How to use my custom menus as seperate pages?
- Add class to current category menu item
- WordPress wp get nav menu items does not deliver external link
- wp_nav_menu changed to wp_page_menu
- how to assign an ID to a wordpress menu
- Site pages show the page title under navigation bar
- Keeping my Sub Menu open when hovering on its list items
- Jquery dropdown menus working locally, but not in WordPress [duplicate]
- Wrapping my ‘s with
- WordPress “add to menu” button not working
- Primary menu shortcode name
- register_nav_menus and wp_nav_menu issue, not displaying independent menus
- Convert a custom bootsrap based menu to wordpress nav walker
- How do I get the menu items based on name or ID?
- Menu problem : when add wordpress element in menu it convert into empty custom link
- Problems with the navigation menu