最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

logout - What is the link to log out on Wordpress?

programmeradmin0浏览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:

.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
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论