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

本文介绍如何在Wordpress中自定义作者页面的URL结构,通过修改functions.php文件中的代码实现将默认的author部分替换为自定义的slug。
1814

被折叠的 条评论
为什么被折叠?



