Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    since EM is using custom post type maybe you can try something similar to this thread – https://wordpress.org/support/topic/custom-post-type-highlighting-current-menu-item?replies=5

    Thread Starter Vasco_r6

    (@vasco_r6)

    I’ve placed this code in functions.php of the theme but it doesn’t work:

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    // highlight active custom post page in nav
    add_filter( 'nav_menu_css_class', 'namespace_menu_classes', 10, 2 );
    function namespace_menu_classes( $classes , $item ){
    	if ( get_post_type() == 'events-manager' ) {
    		// remove unwanted classes if found
    		$classes = str_replace( 'current_page_parent', '', $classes );
    		// find the url you want and add the class you want
    		if ( $item->url == '/events' ) {
    			$classes = str_replace( 'menu-item', 'menu-item current_page_parent', $classes );
    		}
    	}
    	return $classes;
    }

    This bit…

    get_post_type() == 'events-manager'

    …is wrong. The post type should be event.

    Thread Starter Vasco_r6

    (@vasco_r6)

    Thanks, this solved my problem for the parent butnot for the childs.

    add_filter( 'nav_menu_css_class', 'namespace_menu_classes', 10, 2 );
    function namespace_menu_classes( $classes , $item ){
    	if ( get_post_type() == 'event' ) {
    		// remove unwanted classes if found
    		$classes = str_replace( 'current_page_parent', '', $classes );
    		// find the url you want and add the class you want
    
    		$url = $item->url;
    		if ( strpos($url, 'events' ) !== false){
    			$classes = str_replace( 'menu-item', 'menu-item current_page_parent', $classes );
    		}
    
    	}
    	return $classes;
    }

    ex.
    parent “events”
    — child “events/category”
    — child “events/locations”
    Any suggestion?

    You might want to try

    !=== false

    instead of

    !== false

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Navigation problem’ is closed to new replies.