• Resolved gcordero

    (@gcordero)


    Hello
    After closing the session, the user goes to the wordpress login page but I want the user to remain on the same page from which he or he disconnects. The wordpress login page takes the user out of the website’s environment (plus he has already been logout and don’t need to access again!).
    How can I redirect the user to the same page where is he?
    Thanks!

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Max K

    (@kaminskym)

    Hi,

    Try the following code for redirect to the home:

    add_action('wp_logout','auto_redirect_after_logout');
    function auto_redirect_after_logout(){
      wp_redirect( home_url() );
      exit();
    }

    Or you can use

    $_SERVER[‘HTTP_REFERER’]

    For redirect to refer page replace:

    wp_redirect( home_url() );

    with

    wp_safe_redirect( esc_url($_SERVER['HTTP_REFERER']) );

    Thread Starter gcordero

    (@gcordero)

    Please, explain me, I don’t know about php.
    With the code in function.php nothing happens.

    add_action(‘wp_logout’,’auto_redirect_after_logout’);
    function auto_redirect_after_logout(){
    wp_safe_redirect( esc_url($_SERVER[‘HTTP_REFERER’]) );
    exit();
    }

    I need the user to simply stop being connected and to stay on the same page from where he was. Should there be any url indicated?
    I hope your help, thank!

    Thread Starter gcordero

    (@gcordero)

    OK, I solved it with another plugin. Thank!

    Plugin Author Max K

    (@kaminskym)

    For all future users:

    Here is a code if you want just redirect after user approving: https://monosnap.com/file/DMECYe8nQFWzjFJbkMEuhpT3IeBMjX

    add_action(‘wp_logout’,’auto_redirect_after_logout’);
    function auto_redirect_after_logout(){
    wp_redirect( home_url() );
    exit();
    }

    Or if you want to remove the approve screen and redirect to home.

    add_action( ‘check_admin_referer’, function($action, $result) {
    if ( ‘log-out’ == $action && is_user_logged_in() && !empty($_GET[‘action’]) && ‘logout’ == $_GET[‘action’] ) {
    wp_logout();
    wp_redirect( home_url() );
    exit();
    }
    } );

    N/A

    • This reply was modified 6 years, 3 months ago by wpluvr360.
    • This reply was modified 6 years, 3 months ago by wpluvr360.

    N/A

    • This reply was modified 6 years, 3 months ago by wpluvr360.
    • This reply was modified 6 years, 3 months ago by wpluvr360.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Redirect after logout’ is closed to new replies.