I have a custom login form that takes the code from wp-login.php.
I can't use wp-login.php because when this file is used I refer them to my main login file, ie login.php.
Is there therefore a link or function that I can use to log out via the login.php page and not wp-login.php?
I also tried to use the following code but without success:
.php?action=logout
Thanks to those who will help me.
UPDATE:
I also tried to modify the following function and then apply it to a menu item but it still doesn't work.
function wp_new_logout_url( $redirect = '' ) {
$args = array( 'action' => 'logout' );
if ( ! empty( $redirect ) ) {
$args['redirect_to'] = urlencode( $redirect );
}
$logout_url = add_query_arg( $args, site_url( 'login.php', 'login' ) );
$logout_url = wp_nonce_url( $logout_url, 'log-out' );
return apply_filters( 'logout_url', $logout_url, $redirect );
}
This is where it is applied:
<a href="<?php echo wp_new_logout_url(); ?>">Logout</a>
I have a custom login form that takes the code from wp-login.php.
I can't use wp-login.php because when this file is used I refer them to my main login file, ie login.php.
Is there therefore a link or function that I can use to log out via the login.php page and not wp-login.php?
I also tried to use the following code but without success:
https://example/login.php?action=logout
Thanks to those who will help me.
UPDATE:
I also tried to modify the following function and then apply it to a menu item but it still doesn't work.
function wp_new_logout_url( $redirect = '' ) {
$args = array( 'action' => 'logout' );
if ( ! empty( $redirect ) ) {
$args['redirect_to'] = urlencode( $redirect );
}
$logout_url = add_query_arg( $args, site_url( 'login.php', 'login' ) );
$logout_url = wp_nonce_url( $logout_url, 'log-out' );
return apply_filters( 'logout_url', $logout_url, $redirect );
}
This is where it is applied:
<a href="<?php echo wp_new_logout_url(); ?>">Logout</a>
Share
Improve this question
edited Sep 12, 2019 at 11:42
Matteo Feduzi
asked Sep 4, 2019 at 14:26
Matteo FeduziMatteo Feduzi
291 silver badge9 bronze badges
1 Answer
Reset to default 0Yes, the code on your login.php?action=logout page can call wp_logout() to log out.
You probably also want to hook the logout_url filter to generate your new logout URL, else menu bars and the admin site will still try to use wp_login.php.