Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Wrong menu class for Portfolio post

Open dk-wordpress opened this issue 9 years ago • 3 comments

Hi guys

I noticed that when you on single Portfolio project post, "Blog" menu item always has "current_page_parent" class, even if it does not contain this post as child menu element. Is there any way to fix it?

Mega menu extension is active on my installation

2017-05-26_17-49-49

dk-wordpress avatar May 26 '17 15:05 dk-wordpress

But where directs your Portfolio page?

GheorgheP avatar May 29 '17 06:05 GheorgheP

Hey! In my case, "Portfolio" is a standard page, this is not Portfolio Archive link. The problem is that "Blog" should be not highlighted in any case, since this menu item has no any portfolio post child links

dk-wordpress avatar May 29 '17 07:05 dk-wordpress

i investigated the problem, and it seems this is not Unyson problem, it's WordPress. I resolved this with following code:

add_filter( 'nav_menu_css_class', 'modify_nav_classes', 10, 2 );

function modify_nav_classes( $classes, $item ) {
  if( ( is_post_type_archive( 'fw-portfolio' )
  || is_singular( 'fw-portfolio' ) )
  && $item->object_id == get_option('page_for_posts') ){
    $classes = array_diff( $classes, array( 'current_page_parent' ) );
  }
  return $classes;
}

dk-wordpress avatar May 31 '17 09:05 dk-wordpress