Created
October 24, 2018 22:43
-
-
Save cameronjonesweb/4279f77b39687091a32aa4df178d7877 to your computer and use it in GitHub Desktop.
Removes the `current_page_parent` class from the blog page link when not viewing a blog related page
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 | |
/** | |
* Removes the `current_page_parent` class from the blog page link when not viewing a blog related page | |
* | |
* @param array $classes The CSS classes that are applied to the menu item's `<li>` element. | |
* @param WP_Post $item The current menu item. | |
* @param stdClass $args An object of wp_nav_menu() arguments. | |
* @param int $depth Depth of menu item. Used for padding. | |
*/ | |
function cameronjonesweb_remove_current_page_parent( $classes, $item, $args, $depth ) { | |
// Fix the current_page_parent class being added to custom post type archives. | |
if ( in_array( 'current_page_parent', $classes, true ) ) { | |
$blog_page = get_option( 'page_for_posts' ); | |
if ( ! is_home() && ! is_singular( 'post' ) && ! is_category() && ! is_tag() && ! is_author() && wp_get_post_parent_id( $item->object_id ) !== $blog_page ) { | |
$key = array_search( 'current_page_parent', $classes, true ); | |
unset( $classes[ $key ] ); | |
} | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment