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'm using Bill Erickson's "Add Extra Code to Any Menu" function:

<?php
/**
 * 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>';
else
    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
add comment

1 Answer

up vote 1 down vote accepted

I think the reason is echo vs return:

The function posts_logout_link from

http://plugins.svn.wordpress.org/logout-password-protected-posts/trunk/logout.php

is using echo.

Your code is therefore both returning and echoing values.

ps: You could consider using output buffering to fix this

ob_start();
do_action('posts_logout_link');
$logout_link=ob_get_clean();

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
add 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.