WordPress.org

Ready to get started?Download WordPress

Forums

Simple Portfolio
Fix for wp_nav_menu current css class (2 posts)

  1. Steven Vachon
    Member
    Posted 1 year ago #

    function nav_list_portfolio_bugfix($classes, $item)
    {
    	if (get_post_type() == 'portfolio')
    	{
    		// Change value to match the slug for your portfolio wordpress page
    		$page = get_page_by_path('portfolio');
    
    		if ($page)
    		{
    			if ($page->ID != $item->object_id)
    			{
    				foreach ($classes as $key => $value)
    				{
    					if ($value == 'current_page_parent')
    					{
    						unset($classes[$key]);
    						break;
    					}
    				}
    			}
    			else
    			{
    				array_push($classes, 'current_page_parent');
    			}
    		}
    	}
    
    	return $classes;
    }
    
    add_filter('nav_menu_css_class',  'nav_list_portfolio_bugfix', 10, 2);

    http://wordpress.org/extend/plugins/simple-portfolio/

  2. Steven Vachon
    Member
    Posted 1 year ago #

    Update. Change this:

    array_push($classes, 'current_page_parent');

    to this:

    // 'current-menu-item' added for compatibility with other plugins
    array_push($classes, 'current_page_parent', 'current-menu-item');

    If it creates a problem with your code, just use the original line.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.