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 looking for a function that can redirect users when they logout to the current page. I'm looking for a code I can use in functions.php?

share|improve this question

3 Answers 3

Using this code in functions.php does trick for me.

function wpse_44020_logout_redirect($logouturl, $redir)
    {
        return $logouturl . '&redirect_to='.get_permalink();
    }
add_filter('logout_url', 'wpse_44020_logout_redirect', 10, 2);

Note - Above code work only on non admin pages, to make work that on any page you should replace

return $logouturl . '&redirect_to='.get_permalink();

with

return $logouturl . '&redirect_to=http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
share|improve this answer

Have a look here - http://codex.wordpress.org/Function_Reference/wp_logout_url

Easy as adding this:

<a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>
share|improve this answer
    
I need it for the function-file. Not as a link, but thanks for the try :) –  Demilio Mar 1 '12 at 13:05
     add_filter('logout_url', create_function(false, "return '" .  wp_logout_url(get_option("home")) . "';"));  

or change home url to current page url

share|improve this answer
2  
Please add some context to this answer - how does it add substance to what amit said a few months back? –  Johannes Pille Apr 11 '13 at 6:01
1  
This callback would call itself in an infinite recursion. Please test your code before you post it. –  toscho Apr 11 '13 at 6:16

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.