Wordpress修改Author頁面URL地址

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)這個方法,所以可以直接調用來替換categorybase(默認爲category)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章