Even when viewing single blog posts it is still nice to have the "Blog" nav menu link show the active status to give a feel for site hierarchy.
With this snippet you can match the nav link text with a conditional tag to add the
The example below targets a nav menu link labeled "Blog" and also highlights it when you are viewing category pages and single blog posts. You can also add more conditionals to target other text links like I have with the Stream.
Paste to your
With this snippet you can match the nav link text with a conditional tag to add the
current-menu-item
class to a specific text string.The example below targets a nav menu link labeled "Blog" and also highlights it when you are viewing category pages and single blog posts. You can also add more conditionals to target other text links like I have with the Stream.
Paste to your
functions.php
file.
PHP:
<?php
/**
* Make nav menus active on other types of pages.
*
* @since 1.0
*/
function md_child_current_menu_item( $classes, $item ) {
if (
( $item->title == 'Blog' && ( is_category() || is_singular( 'post' ) ) ) ||
( $item->title == 'Stream' && ( is_tax( 'stream_categories' ) || is_singular( 'stream' ) ) )
)
$classes[] = 'current-menu-item';
return $classes;
}
add_filter( 'nav_menu_css_class', 'md_current_menu_item', 10, 2 );