WordPress log out according to url Parameter

I need to log out the logged in user through the URL without going to log-in page or log out confirmation.Is it possible?

For example:

Read More

I am taking the URL mysite.com/testpage?logout=1. If the logout parameter is available in URL i need to log out the user without any log out confirmation and go to the mysite.com/testpage page is it possible?

please suggest any option for this

thanks in advance

Related posts

3 comments

  1. You’re looking for WordPress’s get_query_var(). For example, you could define a function such as the following:

    if ( get_query_var('logout') == '1' ) {
        // Log the user out
        // Codex: https://codex.wordpress.org/Function_Reference/wp_logout
    }
    
  2. you can use the wp_logout_url() function.

    Example:

    <a href=" <?php echo wp_logout_url(home_url('login')) ?> ">Logout</a>
    
  3. Please use this following code :

    if ( get_query_var('logout') == '1' ) 
    {
        $redirect_url=home_url();
        wp_logout(); 
        wp_redirect($redirect_url);
    }
    

    Hope it will work for you.

Comments are closed.