Skip to content

wp_list_pages() not setting .current_page_item classes on custom post types

A rather frustrating bug that I became aware of when generating navigational menus for custom post types using wp_list_pages(). The list entries aren’t decorated with useful classes denoting the current item, the parent item, and ancestor(s).

Read about the issue here. Read about working solutions here. I’ve included the solution that I went with, in case you’re looking for a quick fix and no reading.

add_filter('page_css_class', function($classes, $page) {
  global $post;
  if('YourCustomType' == get_post_type($post) && $post->ID == $page->ID)
    $classes []= 'current_page_item';
  return $classes;
}, 10, 2);