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.

  • 2
    I think this might help you out: wordpress.stackexchange.com/a/206536/105535
    – funkysoul
    Commented Feb 18, 2017 at 12:28
  • 1
    @Fayaz current_page_parent is a classname WordPress adds.
    – David Lee
    Commented Feb 18, 2017 at 13:54
  • @DavidLee thanks for the info. I need to spend more time on theme stuffs :)
    – Fayaz
    Commented Feb 18, 2017 at 14:08

1 Answer 1


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
    Commented Feb 19, 2017 at 7:10

Your Answer

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

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