I have set a page to be the posts page. So when I visit single posts the link for posts page in nav menu has a class 'current_page_parent'.

But when I visit single posts for a custom post type, then also it is adding 'current_page_parent' to the link for posts page.

How can I restrict it and not add the class when I visit single custom post types page.


I assuming you're using wp_page_menu() or wp_list_pages(). If so, then what you need to do is hook into the page_css_class filter, e.g.,

add_filter ('page_css_class', 'my_func', 10, 5) ;

my_func ($classes, $page, $depth, $args, $current_page_id)
    if (/* test condition */) {
        $classes = array_diff ($classes, array ('current_page_parent')) ;

    return ($classses) ;

where /* test condition */ is where you'd put your logic to decide when that class should be included.

  • thanks for the code. I used the nav_menu_css_class hook to solve the issue – Kiran Dash Feb 19 '17 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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