I want to logout a user if the user click on custom page link (e.g. example/logout). I need to do that because my site users are not allowed to access wp-login.php page. I've a front-end login page but don't have logout page.
How can I make custom page as logout link? With or without shortcode.
I want to logout a user if the user click on custom page link (e.g. example.com/logout). I need to do that because my site users are not allowed to access wp-login.php page. I've a front-end login page but don't have logout page.
How can I make custom page as logout link? With or without shortcode.
yes we make custom page as logout link on this way add this in function.php
add_action( 'init', 'log_out_user' );function log_out_user() {
global $wp;
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; //get current page url
if(!empty(get_current_user_id()) && $url == 'example.com/logout' ) //check if user is logged in and current page url
{
wp_logout(); //this will logout user
$siteUrl = site_url(); //get site url
wp_redirect($siteUrl);//add this if you want to redirect to site url after logout
}}
wp_logout_url()
returns the link to logout. – Max Yudin Commented Jul 2, 2019 at 8:03