WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Bill Erickson's "Add Extra Code to Any Menu" function:

 * Add Extra Code to Any Menu
 * @author Bill Erickson
 * @link http://www.billerickson.net/customizing-wordpress-menus/
 * @param string $menu
 * @param object $args
 * @return string modified menu
function be_menu_extras($menu, $args) {
//$extras = '<li class="right">Your extras go here</li>';
if ('secondary' == $args->theme_location) 
    //return $menu . $extras;
      return $menu . '<li>' . do_action('posts_logout_link') . '</li>';
    return $menu;
add_filter('wp_nav_menu_items','be_menu_extras', 10, 2);

to insert do_action('posts_logout_link'); from the Logout Password Protected Posts plugin.

Can anyone shed some light as to why do_action appears outside the $menu.

If I use html, it appears at the end on the menu wrapped in the <li> tags, as it's supposed to. (Using $extras seemed to duplicate the link in other areas.)

share|improve this question
up vote 1 down vote accepted

I think the reason is echo vs return:

The function posts_logout_link from


is using echo.

Your code is therefore both returning and echoing values.

ps: You could consider using output buffering to fix this


return $menu . '<li>' . $logout_link . '</li>';

or modify the plugin code functions to your needs and place them into your functions.php file.

share|improve this answer
Thank you. I just ended up using the posts_logout_url(). Perfect. – Ina Feb 15 '13 at 2:39

Your Answer


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.