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.

Right now when I log out via:

<a href="<?php bloginfo('url'); ?>/wp-login.php?action=logout">Log out</a>

it redirects me to the page where I need to confirm the log out.

How to eliminate the confirmation and redirect to the homepage after logout?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

This happens because you are missing the neccessary nonce in the URL, which is being checked in wp-login.php

case 'logout' :
    check_admin_referer('log-out');
    ...

Use wp_logout_url in order to retreive the URL including the nonce. If you want to redirect to a custom URL, simply pass it as an argument.

<a href="<?php echo wp_logout_url('/redirect/url/goes/here') ?>">Log out</a>

You could also use wp_loginout which generates the link for you including translation:

echo wp_loginout('/redirect/url/goes/here')
share|improve this answer

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.