0

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.com/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>

1 Answer 1

0

Yes, 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.

1
  • I updated the question, thanks for the reply Sep 4, 2019 at 16:10

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.