WordPress Snippet
Last active
February 28, 2018 18:00
-
-
Save ControlledChaos/b581a05ff08b20f0c001f029b307af2b to your computer and use it in GitHub Desktop.
Add a current class to post type parent in WordPress nav menus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add current class to post type parent in nav menus. | |
*/ | |
function ccd_custom_active_item_classes( $classes = [], $menu_item = false ) { | |
global $post; | |
$classes[] = ( $menu_item->url == get_post_type_archive_link( $post->post_type ) ) ? 'current-menu-item active' : ''; | |
return $classes; | |
} | |
add_filter( 'nav_menu_css_class', 'custom_active_item_classes', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment