How to load shortcode sooner

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.

Read More

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

Related posts

Leave a Reply

2 comments

  1. $myfunction= '[bc_user_groups amount="20"]';
    $myfunction_parsed = do_shortcode($myfunction);
    

    became

    $atts = array( 'amount' => 20 );
    $myfunction_parsed = bc_user_groups( $atts );
    

    Call the shortcode function (I asume your shortcode function name is ‘bc_user_groups’) direct.

  2. From a bit of googling I found some useful information,

    You add this to your theme’s functions.php

    add_filter(‘item_to_hook_to’, ‘do_shortcode’, 9);

    If you are using the WP navigation structure you can hook to ‘wp_nav_menu’. As you can see the ‘9’ represents the priority setting allowing you to control the load order.

    links to information: –

    Good explanation of shortcodes – look at bottom of article for priority reference

    add_filter with parameter description

    If you find this to be unsuccessful try to change the priority setting or find something else to hook to by referencing the hooks list before your menu loads, hope this helps

    I can’t add more than 2 links because of lack of posts but the hook list can be found at the following or even at wordpress site

    http:// adambrown.info/p/wp_hooks/hook