简体   繁体   English

当用户在wordpress中按登出按钮时,重定向到登录页面

[英]redirect to login page when user press logout in wordpress

I have a problem when user clicks on logout, he's getting redirected to wordpress's login page, whereas I want him to be redirected to website's login page. 当用户单击注销时,我遇到了问题,他被重定向到了wordpress的登录页面,而我希望他被重定向到网站的登录页面。

Here's the header link I'm trying, but it's not working : 这是我正在尝试的标题链接,但它不起作用:

header("Location:http://".$_SERVER['HTTP_HOST']."/ngo/wp-login.php?action=logout".
           "&redirect_to=http://".$_SERVER['HTTP_HOST']."/ngo/?page_id=56");

get_header();

ngo/?page_id=56 is the permalink to the login page. ngo/?page_id=56是登录页面的永久链接。

Something like this: 像这样:

add_action( 'wp_logout', 'my_redirect' );

function my_redirect() {
    wp_redirect( 'http://whatever_you_like.com' );
}

WordPress has a hook system where you can hook to most significant moments. WordPress有一个挂钩系统,您可以在其中挂钩最重要的时刻。 With the code above we simply say we want to handle something on log out and where is our handler callback. 使用上面的代码,我们只是说我们要在注销时处理某些内容,并且处理程序回调在哪里。

I can give you also OOP style, if you have class. 如果您有课程,我也可以给您OOP风格。

Try using the WP function for that purpose. 为此,请尝试使用WP 函数 The parameter is the URL to redirect to on logout. 该参数是注销时重定向到的URL。 :

<?php echo wp_logout_url( $redirect ); ?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM