How to automatically log out when you visit a page on WordPress

0
192

I need it a simple script that would help me to logout automatically the user when they reached a specific page.

I did not wish to do a lot of codding and create a plugin for this but use a more direct approach.

I have gone into the WordPress folder. Then selected  /wp-content/themes/[currenttheme]/header.php. In the begin of the page i add the following code:

$url = explode("?",$_SERVER["REQUEST_URI"]);
if($url[0]=="your url without domain") { //example url: /product/
        if(is_user_logged_in()){
            wp_logout();
            header("location:your url without domain");
            die();
        }
}

This works great.

LEAVE A REPLY

Please enter your comment!
Please enter your name here