admin管理员组文章数量:1122846
I have a custom post type "treatment", under this CPT the taxonomy "treatment_category" which forntend slug is "category"
right now the URL for category displaying as follows.
www.MYDOMAIN.COM/category/practitioner-london/
Just want to remove the slug "category" and display as
www.MYDOMAIN.COM/practitioner-london/
also the post URLs like this
www.MYDOMAIN.COM/treatment/practitioner-london/dermal-filler-london/
also want to change this to as below by removing "treatment"
www.MYDOMAIN.COM/practitioner-london/dermal-filler-london/
is this possible.
I have a custom post type "treatment", under this CPT the taxonomy "treatment_category" which forntend slug is "category"
right now the URL for category displaying as follows.
www.MYDOMAIN.COM/category/practitioner-london/
Just want to remove the slug "category" and display as
www.MYDOMAIN.COM/practitioner-london/
also the post URLs like this
www.MYDOMAIN.COM/treatment/practitioner-london/dermal-filler-london/
also want to change this to as below by removing "treatment"
www.MYDOMAIN.COM/practitioner-london/dermal-filler-london/
is this possible.
Share Improve this question asked Mar 31, 2024 at 6:10 user1419170user1419170 1012 bronze badges 2- You can try plugin wordpress.org/plugins/remove-category-url. For me, I still prefer to keep the category – Công Tử Huyết Commented Mar 31, 2024 at 15:24
- Thanks, I tried but not the solution I want. – user1419170 Commented Apr 1, 2024 at 9:25
1 Answer
Reset to default 0yes, possible to achieve the URL structure you desire by modifying the permalink structure for your custom post type and taxonomy.
Firslty flush the rewrite rules by visiting the permalink settings page in your Wp admin area Settings > Permalinks
and clicking Save Changes
. This will regenerate the rewrite rules and apply your custom permalink structure.
After adding the below code in your current active theme functions.php
file or your custom plugin.
Remove treatment_category
from the category URL
add_action('init', 'custom_taxonomy_rewrite_rule');
function custom_taxonomy_rewrite_rule() {
$taxonomy_slug = 'treatment_category'; // Change this to your taxonomy slug
$taxonomy = get_taxonomy($taxonomy_slug);
$taxonomy->rewrite['slug'] = ''; // Set the slug to empty to remove "category" from the URL
}
Remove treatment
from the post URL
add_action('init', 'custom_post_type_rewrite_rule');
function custom_post_type_rewrite_rule() {
$post_type_slug = 'treatment'; // Change this to your custom post type slug
$post_type = get_post_type_object($post_type_slug);
$post_type->rewrite['slug'] = ''; // Set the slug to empty to remove "treatment" from the URL
}
本文标签: phpRemove slug and custom post type name from URL
版权声明:本文标题:php - Remove slug and custom post type name from URL 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736312134a1934990.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论