您需要3个简单的函数和挂钩
首先更改作者库:
//change author/username base to users/userID
function change_author_permalinks() {
global $wp_rewrite;
// Change the value of the author permalink base to whatever you want here
$wp_rewrite->author_base = \'users\';
$wp_rewrite->flush_rules();
}
add_action(\'init\',\'change_author_permalinks\');
然后将用户添加到query\\u vars:
add_filter(\'query_vars\', \'users_query_vars\');
function users_query_vars($vars) {
// add lid to the valid list of variables
$new_vars = array(\'users\');
$vars = $new_vars + $vars;
return $vars;
}
然后添加新的重写规则:
function user_rewrite_rules( $wp_rewrite ) {
$newrules = array();
$new_rules[\'users/(\\d*)$\'] = \'index.php?author=$matches[1]\';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter(\'generate_rewrite_rules\',\'user_rewrite_rules\');
现在,如果您不知道如何使用它,只需复制所有代码并粘贴到主题函数中即可。php文件。