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)。

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