使用短代码在Wordpress中加载两个单独的菜单

问题描述:

Currently using this code in my Wordpress menu system to load the menu.

    <div id='navbar' class='collapse navbar-collapse'>
<?php if ( function_exists('max_mega_menu_is_enabled') && max_mega_menu_is_enabled('primary') ) : ?>
    <?php wp_nav_menu( array( 'theme_location' => 'primary') ); ?>
    <?php else: ?> 
    <?php
    if ( has_nav_menu( 'primary' ) ) :
    wp_nav_menu( array(

    'theme_location' => 'primary',
    'container'      => false,
    'menu_class'     => 'main-navigation',
    'walker'         => new Aria_Walker_Nav_Menu(),
    'items_wrap'     => '<ul id="%1$s" class="%2$s" role="menubar">%3$s</ul>',
    ) ); 
    endif;
    ?>
    <?php endif; ?> 

    </div>

I am also using a plugin that allows me to switch out content based on location of the user using a shortcode.

Here is the short code

    <?php echo do_shortcode("[CBC show='y' country='us'] Content to switch out goes here [/CBC]

I've also created a menu called 'services' aside from the 'primary' one. I've tried to implement the do_shortcode method to attempt to switch out the lines that have 'primary' for 'services' but keep getting errors.

I'm not sure if I'm having syntax errors or if it isn't possible.

I've successfully used the do_shortcode method in our footer like this to swap out sticky mobile buttons and it works:

    <?php echo do_shortcode("[CBC show='y' country='us'] <a class='call-now' id='track-calls' href='tel:555-555-5555'><i class='fa fa-mobile'></i> CALL US</a>[/CBC]"); ?>
    <?php echo do_shortcode("[CBC show='y' country='us'] <a class='schedule-now' id='book-now' href='http://example.com'><i class='fa fa-calendar'></i> BOOK NOW</a>[/CBC]"); ?>
    <?php echo do_shortcode("[CBC show='y' country='tt'] <a class='call-now' id='track-calls' href='tel:555-555-1234'><i class='fa fa-mobile'></i> CALL US</a>[/CBC]"); ?>
    <?php echo do_shortcode("[CBC show='y' country='tt'] <a class='schedule-now' id='book-now' href='http://example.com'><i class='fa fa-calendar'></i> BOOK NOW</a>[/CBC]"); ?>

I was able to find a solution. I used the class option in the Wordpress menu and just gave each menu item I wanted to appear in the US only a class and same for Trinidad/Tobago. Then used the php do_shortcode method and used css via in the header of the website.

Here is the code for anyone that may want to do similar in the future.

    <?php echo do_shortcode("[CBC show='y' country='us'] <style> li.trinidad { display:none; } li.usa-menu { display:inline-block; } </style>[/CBC]"); ?>
    <?php echo do_shortcode("[CBC show='y' country='tt'] <style> li.trinidad { display:inline-block; } li.usa-menu { display:none; } </style>[/CBC]"); ?>

The plugin I am using for the functionality is: Custom Content by Country (from iControlWP) by One Dollar Plugin.