Skip to content

Instantly share code, notes, and snippets.

@cadic
Last active June 9, 2016 20:00
Show Gist options
  • Save cadic/fee99d2faa40c29373edcf5b4f73bb55 to your computer and use it in GitHub Desktop.
Save cadic/fee99d2faa40c29373edcf5b4f73bb55 to your computer and use it in GitHub Desktop.
Wordpress: highlight "Blog" menu item when displaying single posts or archives
<?php function ml_menu_item_classes( $classes, $item, $args ) {
if( ( is_singular( 'post' ) || is_category() || is_tag() ) && $item->object_id == get_option( 'page_for_posts', 0 ) )
$classes[] = 'current-menu-item';
return array_unique( $classes );
}
add_filter( 'nav_menu_css_class', 'ml_menu_item_classes', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment