2011-10-08 65 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中,它會在登錄時重定向用戶。 希望幫助:)

相關問題