site_url()調用函數get_site_url(),它在您的wp_options表中查找名爲「site_url」的選項。更改配置文件不會對它產生任何影響。
你可以做的是在你需要使用別的東西的頁面上對site_url應用一個過濾器。在get_site_url()函數的最後一部分內容:
return apply_filters('site_url', $url, $path, $scheme, $blog_id);
所以,如果你想修改返回添加像這樣到主題functions.php文件中的值:
add_action('template_redirect', 'modify_site_url');
function modify_site_url(){
/** check if you're on one of the pages that requires the change */
if(is_page(array('page-one', 'page-two'))){
add_filter('site_url', 'new_site_url', 10, 4);
}
}
function new_site_url($url, $path, $scheme, $blog_id){
/** modify the url here */
$url = whatever you want it to be;
return $url;
}
在new_site_url函數沒有使用額外的參數($ path,$ scheme,$ blog_id),但你可以使用這些來進一步改進url的修改方式。
再次看看你的問題,我可能誤解了你的意圖。如果您試圖讓某些網頁實際上使用不同的網址,那麼不僅需要更改site_url的值,那麼您必須查看301重定向插件。 site_url()不會影響實際頁面URL(在您的瀏覽器地址欄中)的內容。 – wunderdojo