WordPress.org

Ready to get started?Download WordPress

Forums

Eazyest Gallery
Missing menu item active class (1 post)

  1. klihelp
    Member
    Plugin Author

    Posted 1 year ago #

    Missing menu item active class in navigation.
    Wordpress default themes have their own active classes for menu items, so it would be good to have a filter for the classes.

    /**
     * Fix active class in nav
     *
     * @access public
     * @param array $menu_items
     * @param array $args
     * @return array
     */
    add_filter( 'wp_nav_menu_objects',  'the_ezg_nav_menu_item_classes', 2, 20 );
    function the_ezg_nav_menu_item_classes( $menu_items, $args ) {
    
    	if ( ! get_post_type() == 'galleryfolder' ) return $menu_items;
    
    	global $post;
    	$gallery_page = $post->ID;
    	$page_for_posts = (int) get_option( 'page_for_posts' );
    
    	foreach ( (array) $menu_items as $key => $menu_item ) {
    
    		$classes = (array) $menu_item->classes;
    
    		// Unset active class for blog page
    		if ( $page_for_posts == $menu_item->object_id ) {
    
    			$menu_items[$key]->current = false;
    			unset( $classes[ array_search('current_page_parent', $classes) ] );
    			unset( $classes[ array_search('current-menu-item', $classes) ] );
    
    		// Set active state if this is the page link
    		} elseif ( is_ezg_gallery()
    				&& $gallery_page == $menu_item->object_id
    				) {
    			$menu_items[$key]->current = true;
    			$classes[] = 'current-menu-item';
    			$classes[] = 'current_page_item';
    
    		// Set parent state if this is a single page
    		} elseif ( is_singular( 'galleryfolder' )
    			&& $gallery_page == $menu_item->object_id
    			) {
    			$classes[] = 'current_page_parent';
    		}
    
    		$menu_items[$key]->classes = array_unique( $classes );
    
    	}
    
    	return $menu_items;
    }

    http://wordpress.org/extend/plugins/eazyest-gallery/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic