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.)
I think the reason is
echo
vsreturn
:The function
posts_logout_link
fromhttp://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
or modify the plugin code functions to your needs and place them into your functions.php file.