admin管理员组文章数量:1290927
Alternate Question: How to change Permalink structure for CPT so that post name comes in the middle of URL instead of in the end eg. /a/%postname%/b/c
Any suggestions while changing the permalink structure in custom post type? Right now I want the struct to be /a/%postname%/b/c
but it keeps adding postname in the end by default like /a/%postname%/b/c/%postname%
.
Here's my register_post_type
code,
$args = array(
'label' => __('testCPT', 'text_domain'),
'description' => __('Site articles.', 'text_domain'),
'labels' => $labels,
'supports' => array('title', 'revisions'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array(
'slug' => '/a/%postname%/b/c',
'with_front' => false
),
);
Structure generated:
http://localhost/project/a/yoda/b/c/yoda/
Structure Desired:
http://localhost/project/a/yoda/b/c/
Alternate Question: How to change Permalink structure for CPT so that post name comes in the middle of URL instead of in the end eg. /a/%postname%/b/c
Any suggestions while changing the permalink structure in custom post type? Right now I want the struct to be /a/%postname%/b/c
but it keeps adding postname in the end by default like /a/%postname%/b/c/%postname%
.
Here's my register_post_type
code,
$args = array(
'label' => __('testCPT', 'text_domain'),
'description' => __('Site articles.', 'text_domain'),
'labels' => $labels,
'supports' => array('title', 'revisions'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array(
'slug' => '/a/%postname%/b/c',
'with_front' => false
),
);
Structure generated:
http://localhost/project/a/yoda/b/c/yoda/
Structure Desired:
Share Improve this question edited Jun 4, 2021 at 8:34 mach2 asked Jun 4, 2021 at 8:19 mach2mach2 1134 bronze badgeshttp://localhost/project/a/yoda/b/c/
1 Answer
Reset to default 1Note that you should use %<post type>%
in the slug
value, so if the post type is test_cpt
, then you would use %test_cpt%
as in /a/%test_cpt%/b/c
.
And moving the post name/slug to the middle or beginning in the permalink structure is actually pretty easy:
Register the post type:
// replace test_cpt with the correct post type register_post_type( 'test_cpt', $args );
Then after that, do this:
global $wp_rewrite; // replace test_cpt with the correct post type $wp_rewrite->extra_permastructs['test_cpt']['struct'] = '/a/%test_cpt%/b/c';
And remember to flush the rewrite rules which can be done just by visiting the permalink settings page.
本文标签: custom post typesWhy does wordpress keep adding postname to my CPT39s permalink in the end
版权声明:本文标题:custom post types - Why does wordpress keep adding postname to my CPT's permalink in the end? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741521398a2383206.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论