我解决了我的问题。我所需要的只是WordPress重写API。
if( ! function_exists(\'theme_add_rewrite_rules\') ){
function theme_add_rewrite_rules(){
add_rewrite_rule(
\'^blog/([^/]+)/?$\',
\'index.php?name=$matches[1]\',
\'top\'
);
}
}
add_action( \'init\', \'theme_add_rewrite_rules\');
这解决了wordpress将如何解析URL的问题。问题的一半是如何修改帖子,使链接不包含/en/slug。下面的代码应该可以解决这个问题。
if( ! function_exists(\'rewrite_blog_url\')){
function rewrite_blog_url($url){
if( strpos( $url, \'/en/blog/\' ) >= 0 ){
return str_replace( \'/en/blog/\', \'/blog/\', $url );
}
return $url;
}
}
if( ! function_exists(\'rewrite_blog_post_url\')){
function rewrite_blog_post_url( $url, $post, $leavename ) {
if ( $post->post_type == \'post\' ) {
return rewrite_blog_url($url);
}
return $url;
}
}
add_filter(\'the_permalink\', \'rewrite_blog_url\');
add_filter(\'the_content\', \'rewrite_blog_url\');
add_filter(\'post_link\', \'rewrite_blog_url\');