0

On wordpress multisite, I have added code as bellow to have shared menus for all sites.

<?php
                $blogs = get_sites();
                foreach( $blogs as $b ){
                    $b->blog_id; 
                    //Do stuff

                    switch_to_blog($b->blog_id);
                    wp_nav_menu(array(
                        'theme_location'=>'primary_menu',
                        'menu_class'=>'navbar',
                        'container' => false,
                        'link_before' => '<span class="menu-wrap">',
                        'link_after'=>'</span>',
                        'fallback_cb'    => false,
                        'walker' => new Walker_Nav_Pointers(),
                    )); 
                    restore_current_blog();
                }  

            ?>

But the "current_menu_item" class is showing for multiple sites menu item. Since the page id is same for those 2 pages access 2 subdomins.

How to overcome it?

Page link:

https://theoriatest.com/media-portal/elysium/business-cards/

https://theoriatest.com/media-portal/amara/video-page/

1 Answer 1

0

Have fixed this problem by added a new class "current-site" on the menu.

<?php
            $blogs = get_sites();
            $current_site = get_current_blog_id();
            foreach( $blogs as $b ){
                //$b->blog_id)
                switch_to_blog($b->blog_id);
                if($current_site == $b->blog_id){
                    wp_nav_menu(array(
                        'theme_location'=>'primary_menu',
                        'menu_class'=>'navbar current-site',
                        'container' => false,
                        'link_before' => '<span class="menu-wrap">',
                        'link_after'=>'</span>',
                        'fallback_cb'    => false,
                        'walker' => new Walker_Nav_Pointers(),
                    )); 
                } else {
                    wp_nav_menu(array(
                        'theme_location'=>'primary_menu',
                        'menu_class'=>'navbar',
                        'container' => false,
                        'link_before' => '<span class="menu-wrap">',
                        'link_after'=>'</span>',
                        'fallback_cb'    => false,
                        'walker' => new Walker_Nav_Pointers(),
                    )); 
                }
                restore_current_blog();
            }  

        ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.