LabofOz

Unhighlight Blog from menus when in search

Jan 17th, 2014
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dtbaker_wp_nav_menu_objects($sorted_menu_items, $args){
  2.     // check if the current page is really a blog post.
  3.     global $wp_query;
  4.     global $post;
  5.     $current_page = $post;
  6.     if(!empty($wp_query->queried_object_id)){
  7.         if($current_page && $current_page->post_type=='post'){
  8.             //yes!
  9.         }else{
  10.             $current_page = false;
  11.         }
  12.     }else{
  13.         $current_page = false;
  14.     }
  15.  
  16.     $home_page_id = (int) get_option( 'page_for_posts' );
  17.     foreach($sorted_menu_items as $id => $menu_item){
  18.         if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ){
  19.             if(!$current_page){
  20.                 foreach($sorted_menu_items[$id]->classes as $classid=>$classname){
  21.                     if($classname=='current_page_parent'){
  22.                         unset($sorted_menu_items[$id]->classes[$classid]);
  23.                     }
  24.                 }
  25.             }
  26.         }
  27.     }
  28.     return $sorted_menu_items;
  29. }
  30. add_filter('wp_nav_menu_objects','dtbaker_wp_nav_menu_objects',10,2);
  31. ?>
RAW Paste Data