Skip to content

Instantly share code, notes, and snippets.

@bdeleasa
Created August 25, 2015 14:21
Show Gist options
  • Save bdeleasa/862c4666708d91459432 to your computer and use it in GitHub Desktop.
Save bdeleasa/862c4666708d91459432 to your computer and use it in GitHub Desktop.
Fixes the issue of the Blog menu item and the testimonials archive menu item being 'active' at the same time when using the Testimonials by Woothemes plugin.
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://example.com
* @since 0.0.1
* @package Testimonials_By_Woothemes_Menu_Fix
*
* @wordpress-plugin
* Plugin Name: Testimonials - Menu Fix
* Plugin URI: http://chooserethink.com
* Description: Fixes the issue of the testimonials archive menu item and the Blog menu item being highlighted at the same time on the testimonials archive page.
* Version: 1.0.0
* Author: Brianna Deleasa @ re:think
* Author URI: http://chooserethink.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: telecom-logos
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// Define some constants
define( 'TBWMF_POST_TYPE', 'testimonial' );
add_filter( 'nav_menu_css_class', 'tbwmf_nav_menu_css_class', 10, 3 );
/**
* Fix an issue with both the CPT archive menu item and Blog
* menu item being highlighted at the same time. We only want
* the CPT archive menu item highlighted on the CPT archive page.
*
* @param $classes
* @param $item
* @param $args
* @return mixed
*
* @since 1.0.0
*/
function tbwmf_nav_menu_css_class( $classes, $item, $args ) {
if ( is_singular( TBWMF_POST_TYPE ) || is_post_type_archive( TBWMF_POST_TYPE ) ) {
$blog_page_id = intval( get_option('page_for_posts') );
if( $blog_page_id !== 0 ) {
if( $item->object_id == $blog_page_id ) {
unset( $classes[ array_search( 'current_page_parent', $classes ) ] );
}
}
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment