0

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.

9
  • Are you certain that none of the numerous classes created automatically are sufficient?
    – s_ha_dum
    Apr 5, 2014 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? Apr 5, 2014 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, 2014 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, 2014 at 16:35
  • @s_ha_dum Maybe this clarifies?
    – Max
    Apr 5, 2014 at 16:43

1 Answer 1

0

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()

1
  • 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, 2014 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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