Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created October 24, 2018 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/4279f77b39687091a32aa4df178d7877 to your computer and use it in GitHub Desktop.
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
<?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