2

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.

3

1 Answer 1

2

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

function
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.

1
  • thanks for the code. I used the nav_menu_css_class hook to solve the issue
    – Kiran Dash
    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.