Wordpress修改Author頁面URL地址
阿新 • • 發佈:2019-02-07
Wordpress
預設Author
頁面http://mysite.com/author/authorname
,若想要將author
替換成自定義的slug
,那麼我們需要使用$wp_rewrite
這個全域性物件。
在functions.php
中,新增以下程式碼:
function edit_author_base()
{
global $wp_rewrite;
$author_slug = 'custom-author-slug';
$wp_rewrite->author_base = $author_slug;
}
add_action('init', 'edit_author_base' );
這樣一來,當使用get_author_posts_url
等函式時,獲得的URL
中將會是http://mysite.com/custom-author-slug/authorname
的形式。若要替換成其他值,請自行將$author_slug
這個變數的值改為對應字串即可。
注:WP_Rewrite
這個類中有set_category_base($category_base)
這個方法,所以可以直接呼叫來替換category
的base
(預設為category
)。