仅针对特定类别从WordPress url中删除类别库
我只想从Wordpress URL中删除特定类别的类别库。 例如,我需要更改: mysite.com/category/blog 到 mysite.com/blog 但我想保持其他类别不变: mysite.com/category/songs仅针对特定类别从WordPress url中删除类别库,wordpress,.htaccess,url,Wordpress,.htaccess,Url,我只想从Wordpress URL中删除特定类别的类别库。 例如,我需要更改: mysite.com/category/blog 到 mysite.com/blog 但我想保持其他类别不变: mysite.com/category/songs 我认为它可以通过一些.htaccess规则来实现,但我发现一些通用规则可以删除所有url中的基本类别。您可以通过使用增强的自定义Permalinks Wp插件轻松实现这一点。你只需要去编辑类别,你会看到一个字段来添加你的自定义url 您可以通过使用增强的自
我认为它可以通过一些.htaccess规则来实现,但我发现一些通用规则可以删除所有url中的基本类别。您可以通过使用增强的自定义Permalinks Wp插件轻松实现这一点。你只需要去编辑类别,你会看到一个字段来添加你的自定义url
您可以通过使用增强的自定义Permalinks Wp插件轻松实现这一点。你只需要去编辑类别,你会看到一个字段来添加你的自定义url
无需使用插件,您就可以轻松做到这一点。 通过管理面板 转到设置->永久链接,然后选择默认为自定义 在这里你知道更多。。
无需使用插件,您就可以轻松做到这一点。 通过管理面板 转到设置->永久链接,然后选择默认为自定义 在这里你知道更多。。
这可以通过一些自定义过滤器和操作来完成。 尝试将此代码放在主题的functions.php文件中:
add_filter( 'post_link', 'custom_permalink', 10, 3 );
function custom_permalink( $permalink, $post, $leavename ) {
// Get the categories for the post
$category = get_the_category($post->ID);
if ( !empty($category) && $category[0]->cat_name == "News" ) {
$permalink = trailingslashit( home_url('/'. $post->post_name .'-'. $post->ID .'/' ) );
}
return $permalink;
}
add_action('generate_rewrite_rules', 'custom_rewrite_rules');
function custom_rewrite_rules( $wp_rewrite ) {
// This rule will will match the post id in %postname%-%post_id% struture
$new_rules['^([^/]*)-([0-9]+)/?'] = 'index.php?p=$matches[2]';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
return $wp_rewrite;
}
这将为帖子设置所需的永久链接结构:这可以通过一些自定义过滤器和操作来完成。 尝试将此代码放在主题的functions.php文件中:
add_filter( 'post_link', 'custom_permalink', 10, 3 );
function custom_permalink( $permalink, $post, $leavename ) {
// Get the categories for the post
$category = get_the_category($post->ID);
if ( !empty($category) && $category[0]->cat_name == "News" ) {
$permalink = trailingslashit( home_url('/'. $post->post_name .'-'. $post->ID .'/' ) );
}
return $permalink;
}
add_action('generate_rewrite_rules', 'custom_rewrite_rules');
function custom_rewrite_rules( $wp_rewrite ) {
// This rule will will match the post id in %postname%-%post_id% struture
$new_rules['^([^/]*)-([0-9]+)/?'] = 'index.php?p=$matches[2]';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
return $wp_rewrite;
}
这将为帖子设置您想要的永久链接结构:他只想更改特定类别,而不是所有类别,请阅读问题oops,因此我的第二个答案中有另一个解决方案,更多的是他只想更改特定类别,而不是所有类别,请阅读问题oops,我的第二个答案中有另一个解决方案,更多信息在这里。您可以不使用post_id完成此操作吗?您可以不使用post_id完成此操作吗?任何类似的免费插件?任何类似的免费插件?