Skip to content

How to stop WordPress automatically highlighting the “Blog” page in the menu

So I was playing around with this website, and I noticed when viewing the 404, search and some other custom WordPress pages it would highlight my “Blog” menu with a current_page_parent class. How annoying!

I think I’ve found a fix, it works for me but I would love others to test to confirm.

The code which was automatically highlighting the “Blog” menu item is located in nav-menu-template.php and it looks like this:

if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ) $classes[] = 'current_page_parent';

I didn’t want to modify this core template file, so I found a filter that I could hook into and “reverse” this line of code. Here’s the solution: (add this to your functions.php file)

function dtbaker_wp_nav_menu_objects($sorted_menu_items, $args){
    // check if the current page is really a blog post.
    global $wp_query;
        $current_page = get_post($wp_query->queried_object_id);
        if($current_page && $current_page->post_type=='post'){
            $current_page = false;
        $current_page = false;

    $home_page_id = (int) get_option( 'page_for_posts' );
    foreach($sorted_menu_items as $id => $menu_item){
        if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ){
                foreach($sorted_menu_items[$id]->classes as $classid=>$classname){
    return $sorted_menu_items;

yes, it’s messy – but it works, if someone wants to post a cleaned up version go for it ๐Ÿ™‚

Published inWeb DevelopmentWordPress


  1. Siggi Siggi

    Works for me. Nice. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *