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 am trying to add a function to my custom menu. The menu works, but I have no idea on how to get the custom_execute_shortcode() function to work inside the add_profile_link_to_nav() function.

Any help appreciated.

//--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"> 

function custom_execute_shortcode() {
$myfunction= '[Shortcode]';
$myfunction_parsed = do_shortcode($myfunction);
echo $myfunction_parsed;
}


            <li class="menu-item"> </li>
   </ul> 
</li>
<!--end menu--->
<?php 
} 
}
add_action( "wp_nav_items","add_profile_link_to_nav" );

Thanks, Tim .

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Simple, don't bundle the function inside. Instead, break it out like this:

//--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"> 
            <?php echo custom_execute_shortcode(); ?>
            <li class="menu-item"> </li>
        </ul> 
    </li>
</ul>    <!--end menu--->
    <?php } 
}
add_action( "wp_nav_items","add_profile_link_to_nav" );

function custom_execute_shortcode() {
     $myfunction= '[Shortcode]';
     $myfunction_parsed = do_shortcode($myfunction);
     return $myfunction_parsed;
}
share|improve this answer
    
Hello EAMann, thanks for the responce, I tryed as you suggested but not working. The menu is there the drop down is there but the short code does is not executing. The short code I am using does execute in a php widget –  Tim Mar 27 '12 at 0:54
    
This might be the problem? in my header.php I am executing my "function add_profile_link_to_nav()" with <?php echo add_profile_link_to_nav(); ?>. Would this cause a problem. This short code with in a short code? –  Tim Mar 27 '12 at 1:55
    
Yes. You're echoing a function that doesn't return anything. –  EAMann Mar 27 '12 at 2:56
    
Thanks for the help. –  Tim Mar 27 '12 at 13:36
    
I have continued to google this question and if I have understood correctly shortcodes only execute on pages and posts, so no shortcodes in menus! –  Tim Mar 28 '12 at 18:18
show 1 more comment

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.