to highlight the menu element, you should add the class active. This will work for your photo custom post type.
Concerning your blog posts:
As you can see, in the URL of a blog post there is no post/ which would be necessary for your code to act on. Furthermore, the blog overview page does not equal the custom post rewrite slug.
You could use something like this statement to add the active class for blog posts:
if (
'post' === get_post_type($post->ID)
&& false !== strpos( $menu_slug, 'blog' )
) {
$classes[] = 'current-menu-item';
$classes[] = 'active';
}
Related Posts:
- Adding a Custom Post Type into the menu screen
- Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?
- Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?
- Adding a menu item for a Custom Post Archive
- Adding an Archive of Posts to the Navigation Menu in WordPress 3.0
- Adding custom post type archives to a WordPress menu
- How to add custom post type archive page links to nav menu?
- Remove current_page_parent nav class from blog index when in CPT
- Query menu_order custom post types
- Now can I group custom post types together?
- How to add meta box to backend menu page
- Highlighting current item of custom post types’ sub pages, listed by wp_list_pages
- Hide custom post type from nav menu manager
- wp_list_pages not showing cpt as I expected
- Renaming Menu Item within Admin Menu Section for a Custom Post Type?
- Menu with Automatic Pages Included from Custom Post Type
- Which User Role for Custom Post Type Menu – wp_nav
- Create Custom Post Type Archive Page with Sub Categories Navigation Sidebar
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- Settings page above CPT page in admin section
- Remove current_page_parent from posts page link in WordPress nav menu
- Adding Custom Taxonomy Archive Link to Nav Menu Shows Up As (Invalid)
- Why are navigation items saved in the database?
- Menu highlight custom post type archive
- How do I create an archive page for standard posts?
- ‘Pages’ widget alternative for custom post types?
- Add the current menu item CSS class to a custom page type archive in WordPress menu
- wp_nav_menu() mark current item ancestor of custom post type
- current-menu-item class for custom post type parent
- How to change the admin menu “Pages” to something else
- Menu Multiple Taxonomies
- Navigation menus not showing because of custom post type filter
- Fake mark a menu item as current_page_item/active in WordPress
- Should I use custom menu, C.P.T. or theme options, or something else for this?
- Set menu active state for custom posttype and category, given custom taxonomy term
- Function to display custom post type on front page makes menu items dissapear
- Correct classes for WordPress menu items
- Customize the Dashboard Menu Editor
- How to make this menu drop down or like accordion
- Custom Post Types don’t highlight in menu nav
- Using default WP menu functionality to link to custom post-type listing?
- Second Set of Eyes: One custom taxonomy shows in Appearance > Menus, one does not
- page menu entry for custom post type
- How to display custom WP menus?
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- Use custom walker to add taxonomy terms to main nav menu
- A page that shows a list of a specific custom post type
- Single custom post type’s menu ancestor/parent is Posts archive page
- menu link to custom post_type?
- Review site custom post type structure
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Ordering Submenu Pages in WP 3.1
- Including link to custom post type in ‘wp_list_pages’ function
- Which Template Page Should I Use?
- How can i automatically add CPT single pages as sub menu items
- How can I create an automatic drop down menu with my tags?
- show current item in custom menu, when inside a custom post type
- WordPress menu with custom taxonomy
- Prevent custom post type from showing up in custom menus
- Custom Post Type – Portfolio no longer works
- Custom Posttype and menu classes
- highlight parent page menu item when in custom post type
- Custom post type post in custom menu
- Custom post type posts wont show in wp_nav_menu()
- Home page is getting current-menu-item even if it’s not home
- Placing Admin Post Metaboxes in Tabs
- How can I put content before my custom post type default pages?
- How we can create menu from Appearance > Menu and use as a add-submenu-page for admin menu?
- build child and anchestor three from post parent
- wordpress get menu id by custom post_type?
- wp_get_nav_menu_items doesn’t return custom post type item
- Automatically add CPT UI categories to the menu
- Possition a Custom Post Type Tab under Settings
- wp_nav_menu doesn’t seem to work on custom post type pages
- how to display notifications in the wordpress menu when a new post is published
- Menu disappears with custom post type link
- Use the page picker from wordpress menu creation page
- How to display custom post type in a submenu?
- current_menu_parent for custom post type and custom url
- Calling the first & last post by category in custom post type
- add current-menu-item to multiple custom post types
- Nav style for current page with custom post type
- Admin menu post type
- How to display the FAQ Archive page in my menu
- Custom Taxonomy Showing in WP Menu
- Plugins for putting Custom Post Types into the Menu
- No Current Class showing in Menu for Custom Post Types
- Custom post type in submenu with custom meta box as a title with custom html
- CPT Archive with parent page
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- Setting a Master Menu on a Custom Post Type
- Show posts of parent in edit.php
- and custom post_types to custom menu
- How to make a single Menu Item call another Mega Menu for Custom Post Types and Custom Taxonomies?
- Highlight specific menu item when custom post is page
- Navigation won’t update to show full path to single post
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Can’t add custom post type archive page to menu
- How to build help pages similar to WordPress Developer Resources
- Trying to add CPT to menu automatically