WordPress log out using URL and redirect to specify page

I have one WordPress installation . i need to log out the user without any indication user is coming from particular URL.Is it possible?

My code:

Read More
<?php
if($_GET['logout'] == 1)
{
 $redirect_to = current_page_url(); 
 ?>
 <script>
window.location.href="<?php echo wp_logout_url( $redirect_to ); ?>";
</script>
<?php
}
?>

I am using above code in my header.php . When the user click particular link with log out parameter value is 1. I need to log out the user without any log out confirmation.

I tried with the above code but its asking the following Confirmation.is it possible to avoid this confirmation.

"You are attempting to log out of Learn

Do you really want to log out?"

My requesting URL is like this

http://localhost/learnwordpresslogout=1&redirect='/learnwordpress/category/category1'

I need to log out the user without confirmation and redirect to redirect parameter value URL.Is it possible?

Related posts

2 comments

  1. Try wp_logout() function

    use the funtion .

        if($_GET['logout'] == 1)
        {
        ob_start();
    error_reporting(0);
    wp_logout();
    $redirect = wp_logout_url();
    wp_safe_redirect( $redirect  );
    
    
    
         }
    

Comments are closed.