I am trying to add a shortcode to my menu, the menu item shows up but not the shortcode output.
I think the problem is that the shortcode runs after the menu has run and therefore the shortcode output is not present.
Is there a way to load shortcode sooner?
Thanks
Edit:
Sorry here it is:
//--Nav Menu
function add_profile_link_to_nav(){
if ( is_user_logged_in() ) { ?>
<ul>
<li class="menu-item"id="one"> <a href="http://example.com/members/">All Members</a>
<ul class="sub-menu">
<li class="menu-item"><?php echo custom_execute_shortcode(); ?> </li>
</ul>
</li>
</ul> <!--end menu--->
<?php }
}
add_action( "wp_nav_items","add_profile_link_to_nav" );
function custom_execute_shortcode() {
$myfunction= '[bc_user_groups amount="20"]';
$myfunction_parsed = do_shortcode($myfunction);
return $myfunction_parsed;
}
Edit:
Hello Ralf912, thanks for the response, I am trying to use your suggestion and I am getting this error code: php_code_error:1:/hsphere/local/home/c262876/mydevelepmentsites.com/maol_bp/wp-content/themes/CC-Child-Theme/functions.php:72:Call to undefined function do_bc_user_groups()
Message:A fatal code error occurred.
I have:
//--Nav Menu
function profile_link_to_nav(){
if ( is_user_logged_in() ) { ?>
<ul>
<li class="menu-item"id="one"> <a href="http://example.com/members/">All Members</a>
<ul class="sub-menu">
<li class="menu-item"><?php echo custom_execute_shortcode(); ?> </li>
</ul>
</li>
</ul> <!--end menu--->
<?php }
}
add_action( "bp_menu","profile_link_to_nav",1 );
function custom_execute_shortcode() {
$atts = array( 'amount' => 20 );
$myfunction_parsed =bc_user_groups( $atts );
return $myfunction_parsed;
}
Thanks