0

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.

1

1 Answer 1

0

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
}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.