3

How can I add a logout link in my websites menu? Is there a PHP code or link that I can use to be able to do this?

Thanks

0

1 Answer 1

1

I don't think there is a link that you can use to do it but there is some PHP. I personally like the following tidbit of code to add it.

<?php
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
ob_start();
wp_loginout('index.php');
$loginoutlink = ob_get_contents();
ob_end_clean();
$items .= '<li>'. $loginoutlink .'</li>';
return $items;
}
?>

You can also use this PHP code which basically does the same thing.

add_filter('wp_nav_menu_items','show_register_login_link');
function show_register_login_link($nav) {
    // The "Register" link is not offered if the Administration > Settings > General > Membership: Anyone can register box is not checked.
    return $nav.wp_register("<li class='menu-item'>", "</li>", false)."<li class='menu-item'>".wp_loginout(get_site_url(), false)."</li>";
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.