• Hi,

    Believe me when I say I’ve searched for a solution for this. I’ve tried numerous code snippets but none have worked.

    I have a custom post type of ‘news’ with ‘archive-news.php’ and ‘single-news.php’. When I add post type menu archive item to the main menu and visit the news archive page ‘News’ is highlighted in the menu using the ‘mega-current-menu-item’ class.

    When I click on a news article post the URL changes from domain.com/news to domain.com/news/article-title but news link isn’t highlighted anymore.

    I can’t find a solution that will add the ‘mega-current-menu-item’ class to the News menu item when view the news article.

    Hope this makes sense and someone can point me in the right direction.

    Thanks

    Wayne.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi, i had the same problem previously on TutsInsider(Under dev). I tried all the ways and solutions listed on this page wp_nav_menu( array $args = array() ) but none of them worked for the custom post type.
    So, i dont think that current-menu-item will highlight your active custom post type page or taxonomy.
    Also, if you do find any solution, do tell me.

    Moderator bcworkz

    (@bcworkz)

    How did you add your news post type menu items? If it was picked from the “News” posts list on the left side of the menus screen, it should get the current-menu-item class by default. If it was added as a custom link the current-menu-item mechanism doesn’t work.

    Presumably the mega menu plugin adjusts such classes to get the mega-current-menu-item class. Does the menu item related to the current news page have at least current-menu-item class? It should if it was added from the News posts list.

    Thread Starter deswork

    (@deswork)

    Hi,

    I added the news to the menu using ‘Add menu items’ selecting the News dropdown then adding News from the view all list. It’s showing as a ‘Post Type Archive’ in the menu structure.

    When on the news article page the current-menu-item class is not in the list of classes applied.

    This is the code I used to create the News custom post type.

    $args = array (
    		'labels' => array(
    			'name' => 'News',
    			'singular_name' => 'news',
    		),
    		'hierarchical' => true,
    		'public' => true,
    		'has_archive' => true,
    		'menu_icon' => 'dashicons-text-page',
    		'supports' => array('title', 'editor', 'thumbnail'),
    	);
    	
    	register_post_type('news', $args);
    
    Moderator bcworkz

    (@bcworkz)

    Hmmm… I think the mega menu plugin is messing with the default menu output and it’s failing to properly handle singular custom post type menu items. I suggest seeking assistance from the plugin’s dedicated support channel.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding current-menu-item to custom post type single page’ is closed to new replies.