After changing the Wordpress login URL manually, I was unable to logout

Asked

Viewed 59 times

0

I created a new PHP file instead of wp-login.php and rename it to be my new Login URL. It worked all ok to log in, now when it comes to Logout it returns me to the following URL (wp-login.php?action=logout&_wpnonce=10c62b8542) I mean, I’m not able to do Logout. Would I have to change the logout function in some more file?

1 answer

0

You can do it like this:

In the archive functions.php of your theme, add this code snippet:

// Substitui o link de logout pelo retornado na função heathso_logout_link
add_filter( 'logout_url', 'heathso_logout_link' );
function heathso_logout_link() {
    // Retorna o novo link
    return 'https://seusite.com/logout';
}

Ok, after adding this, you will need to create a custom page called "Logout". To do this, create a new file in your theme called "page-logout.php"

Inside the page "page-logout.php" you will put the code below:

<?php /* Template Name: Logout */
if (is_user_logged_in()) {
   wp_logout();
   wp_redirect( home_url() ); exit;
} else {
   wp_redirect( home_url() ); exit;
}
?>

Soon after adding this file with this code, go to the wordpress administration and create a new page, can call it Logout even, on the right side you will see an option called "Template", select "Logout", save and be happy.

There are better methods to do this by adding custom Endpoints or even calling the function on the page itself if you send a $_GET['logout'];

But to make it easier for you I did it this way :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.