• Skip to primary navigation
  • Skip to main content

Genesis Community

Resources for Genesis WordPress Theme Users

  • Facebook
  • Twitter
  • Slack
  • Wiki
  • Login
You are here: Home / Wikis / WordPress / Add current-menu-item to CPT menu parent when on single entry

Add current-menu-item to CPT menu parent when on single entry

add_action( 'nav_menu_css_class', 'yourprefix_cpt_child_current_menu_item_to_parent_link', 10, 2 );
/**
 * add 'current-menu-item' to menu when on single entry of CPT
 *
 */
function yourprefix_cpt_child_current_menu_item_to_parent_link( $classes, $item ) {

    global $post;

    $id = ( isset( $post->ID ) ? get_the_ID() : NULL );
    if ( isset( $id ) ) :
        $current_post_type = get_post_type_object( get_post_type( $post->ID ) );
        $current_post_type_slug = $current_post_type->rewrite['slug'];
        $menu_slug = strtolower( trim( $item->url ) );
        if ( strpos( $menu_slug,$current_post_type_slug ) !== false) :
            $classes[] = 'current-menu-item';
        endif;
    endif;

    // Return the corrected set of classes to be added to the menu item
    return $classes;
}

Posted by: christina Category: WordPress

« Remove current_page_parent class from blog page menu link when on unrelated CPT or Search Results page
Redirect http traffic to https »

Copyright © 2026 · Genesis Sample on Genesis Framework · WordPress · Log in