function logout_menu_link( $items, $args ) {
if (($args->theme_location == 'main-menu') && (is_user_logged_in())) {
$items .= '<li><a href="'. wp_logout_url() .'">Logout</a></li>';
}
return $items;
}
Also, to put it somewhere other than the last item, here's another example...
function logout_menu_link( $items, $args ) {
{
if( $args->theme_location == 'main-menu' )
{
$new_item = array( '<li><a href="'. wp_logout_url() .'">Logout</a></li>' );
$items = preg_replace( '/<\/li>\s<li/', '</li>,<li', $items );
$array_items = explode( ',', $items );
array_splice( $array_items, 2, 0, $new_item ); // splice in at position 3
$items = implode( '', $array_items );
}
return $items;
}
}
Comments