Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm struggling to get a "current" class for the corresponding menu item when I'm on a singular (child) page of a custom post type. These are the arguments I used when registering the post type with register_post_type:

    array(
        'labels' => array(...),
        'public' => true,
        'has_archive' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'menu_position' => 5,
        'supports' => array('title', 'editor', 'thumbnail'),
        )

On the archive page everything is working fine and I do get the "current-menu-item" class for the current post types menu item. What can I do to make it work? I'm using wp_nav_menu(); to generate the menu.

share|improve this question
    
Are you certain that none of the numerous classes created automatically are sufficient? –  s_ha_dum Apr 5 at 16:02
    
WordPress adds a "current" class, by default. Specifically, .current-menu-item. For hierarchical menu items, WordPress also outputs .current-{post_type}-parent and .current-{post_type}-ancestor. Can you provide a live link to the output? –  Chip Bennett Apr 5 at 16:03
    
@s_ha_dum @Chip Bennet None of the automatically created classes are sufficient. The classes of the corresponding menu item are menu-item menu-item-type-custom menu-item-object-custom menu-item-92 when I'm on a singular page. Unfortunately I don't have a live link right now. –  Max Apr 5 at 16:28
    
What are the classes on the parent items? I'd like to see the menu output as well. –  s_ha_dum Apr 5 at 16:35
    
@s_ha_dum Maybe this clarifies? –  Max Apr 5 at 16:43

1 Answer 1

Given that the markup of your menu does not seems to generating all of the classes I'd expect to see, I'll guess at the problem.

  1. Your theme is using a custom Walker
  2. Or something-- theme or plugin-- has added a filter to (probably) wp_nav_menu_css.
  3. Though there are other filters that could be used.

To fix it, or try to, make sure your theme does not include a walker argument when it calls wp_nav_menu and search your theme and plugins for wp_nav_menu_css and other relevant filters.

If it is a walker you can remove that walker argument, though it may effect other theme functionality. If it is a filter it can be removed with remove_filter()

share|improve this answer
    
Thanks for the answer, but after going every file of my theme through and disabling all plugins, I still haven't found a solution :( Could something be wrong with how I register the post type? –  Max Apr 9 at 18:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.