用户的原始URL如下所示/author/login/
Is it possible to replace login by user\'s id?
在我的梦中,URL应该变成/users/34/
(34是用户id)。谢谢
用户的原始URL如下所示/author/login/
Is it possible to replace login by user\'s id?
在我的梦中,URL应该变成/users/34/
(34是用户id)。谢谢
您需要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文件。您可以使用htaccess规则将/users/34重写为/?作者=34
我构建了一个插件来实现这一点。一位朋友想隐藏作者的URL,因为他不喜欢这些URL显示作者的用户名。我决定更进一步,允许任何用户设置自己的URL。它重定向了他们的旧作者页面。https://wordpress.org/plugins/wp-custom-author-url/
默认作者永久链接为:http://domain.com/author/{username} 我怎么能做这样的事?http://domain.com/author/{username}/songs http://domain.com/author/{username}/books http://domain.com/author/{username}/movies 如果有人访问歌曲permalink,wp应该显示各自作者的歌曲。如果有人访问书籍permalink,wp应