2011-10-08 63 views
-1

我有一个wordpress网站,使用后登录,我希望他们重定向到不同的网站。我如何在wordpress中做到这一点?设置php头功能(头(“位置:http://www.somesite.com”))没有工作,它说头已经在header.php文件中设置。所以基本上我如何通过wordpress重定向?如何重定向到一个WordPress的网站?

是否wordpress有它自己的重定向功能,我可以使用它来安全地重定向到一个WordPress站点?我不知道还有什么可以做的,所以请帮助我,谢谢。

+0

在你的代码中你做重定向? (例如,在页面模板内的什么点等等) – Ben

回答

3

在正常网页中,可以使用wp_redirect(见Function Reference/wp_redirect

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

要允许重定向到其他网站,添加以下functions.php(替换“其他”与你的价值观) :

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

通常情况下,如果在登录页面的URL中的查询字符串redirect_to值,它会尝试验证后重定向到该位置。

要更改登录将用户重定向无论redirect_to查询字符串值,重新添加到functions.php(更换与你的价值观的位置):

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

用于注销,redirectng到另一个站点,你可以然后使用类似的东西:

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

试试这个

//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; 
} 

确保添加你的主机名(您想在allowed_hosts列表重定向)。你可以把这段代码放在你主题的functiions.php中,它会在登录时重定向用户。 希望帮助:)

相关问题