Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
1  
please show us the code you are using. –  Milo Jul 8 '12 at 0:45

2 Answers 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

share|improve this answer
    
Hello thirdOctet, thanks for the response. I had found add_filter('item_to_hook_to', 'do_shortcode', 9); and tried using it but had no luck. But I did not have the link for "List of all WordPress hooks" I have tried about 25 different hooks so far but none of them have worked. Will keep trying, thanks for the time and links the 1st one was a good tutorial on shortcodes. –  Tim Jul 8 '12 at 18:15
    
no worries hope you get your problem sorted out –  thirdOctet Jul 9 '12 at 19:24
$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.

share|improve this answer
    
Hello Ralf912, thanks for the response, I am trying to use your suggestion and I am getting this error: –  Tim Nov 28 '12 at 19:08
    
@Tim undefined function do_bc_user_groups() means that the function wasn't defined at this point. It is clear that a shortcode can not be executed when the shortcode-function wasn't defined. Where is the shortcode registered? In a plugin? Than you can modify the plugin and register the shortcode earlier (e.g. use hook init). Or you can try to include the file with the shortcode-function with the risk of a function already defined error. –  Ralf912 Nov 28 '12 at 22:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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