简体   繁体   English

如何重定向到WordPress网站?

[英]how to redirect out of a wordpress site?

I have a wordpress site, where after use logs in, I want them to redirect to different site. 我有一个wordpress网站,使用后登录后,我希望他们重定向到其他网站。 How can i do this in wordpress? 如何在Wordpress中执行此操作? setting the php header function( header( "Location: http://www.somesite.com " ) ) didn't work, it said headers were already set in header.php file. 设置php标头功能(header(“ Location: http : //www.somesite.com ”))无效,它表示标头已在header.php文件中设置。 So basically how do i redirect via wordpress? 所以基本上我如何通过wordpress重定向?

Does wordpress have it's own re direct function, where i can use it to redirect safely out of a wordpress site? WordPress是否具有自己的重定向功能,在这里我可以使用它来安全重定向到Wordpress网站之外? I have no idea what else to do, so please help me, thanks. 我不知道还能做什么,所以请帮助我,谢谢。

In normal pages, you can use wp_redirect (see Function Reference/wp_redirect ) 在普通页面中,您可以使用wp_redirect (请参见Function Reference / wp_redirect

<?php
wp_redirect( $location, $status );
exit;
?>

To allow redirection to other sites, add the following to functions.php (replacing 'other' with your values): 要允许重定向到其他站点,请将以下内容添加到functions.php (用您的值替换“ other”):

function my_allowed_redirect_hosts($allowed) {
    $allowed[] = 'other.com';
    $allowed[] = 'www.other.com';
    return $allowed;
}
add_filter('allowed_redirect_hosts','my_allowed_redirect_hosts');

Normally, if there is a redirect_to querystring value on the login page's URL, it will attempt to redirect to that location after authenticating. 通常,如果登录页面的URL上有一个redirect_to querystring值,它将在身份验证后尝试重定向到该位置。

To change where the login will redirect users regardless of the redirect_to querystring value, again add to functions.php (replacing the location with your values): 要更改登录名将重定向用户的位置,而不管redirect_to querystring的值如何,请再次添加到functions.php (用您的值替换位置):

function custom_login_redirect() {
  return 'http://www.other.com/Home/Authenticated';
}
add_filter('login_redirect', 'custom_login_redirect');

For logging out and redirectng to another site, you can then use something like: 要注销并重定向到另一个站点,您可以使用类似以下的命令:

<a href="<?=wp_logout_url( "http://other.com/Account/LogOff" )?>">Log Off</a>

Try this one 试试这个

//chage the redirection url for login
add_filter('login_redirect','my_redirect_to_my_site',100,3);
function my_redirect_to_my_site($redirect_to_calculated,$redirect_url_specified,$user){
   return "http://google.com";//where you want to redirect ,change with that

}


//add the domain to allowed hosts list for redirection
add_filter('allowed_redirect_hosts','my_allowed_redirect_hosts');
function my_allowed_redirect_hosts($allowed_hosts){
 $allowed_hosts[]='google.com'; //add the other domain to allowed hosts where to redirect
 return $allowed_hosts;
}

Make sure to add your host name(where you want to redirect in the allowed_hosts list). 确保添加您的主机名(要在allowed_hosts列表中重定向的位置)。 you can put this code in functiions.php of your theme and it will redirect the user on login. 您可以将此代码放在主题的functiions.php中,它将在登录时重定向用户。 Hope that helps :) 希望有帮助:)

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

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