admin管理员组文章数量:1122846
I want to change my custom post URL. I want to remove "item" from URL.
With the below code and with custom post type url plugin / my URL is:
Original URL : http://mywebsite/wp/item/america/mayer/
Want to change it to http://mywebsite/wp/america/mayer/
Without using htaccess
.
WordPress Code
function aitDirItemPostType() {
register_post_type( 'ait-dir-item',
array(
'labels' => array(
'name' => 'Items',
'singular_name' => 'Item',
'add_new' => 'Add new',
'add_new_item' => 'Add new item',
'edit_item' => 'Edit item',
'new_item' => 'New item',
'not_found' => 'No items found',
'not_found_in_trash' => 'No items found in Trash',
'menu_name' => 'Items',
),
'description' => 'Manipulating with items',
'public' => true,
'show_in_nav_menus' => true,
'supports' => array(
'title',
'thumbnail',
'author',
'editor',
'excerpt',
'comments',
),
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => AIT_FRAMEWORK_URL . '/CustomTypes/dir-item/dir-item.png',
'menu_position' => $GLOBALS['aitThemeCustomTypes']['dir-item'],
'has_archive' => true,
'query_var' => 'dir-item',
'rewrite' => array('slug' => 'item'),
'capability_type' => 'ait-dir-item',
'map_meta_cap' => true
)
);
aitDirItemTaxonomies();
flush_rewrite_rules(false);
}
add_action( 'init', 'aitDirItemPostType');
I want to change my custom post URL. I want to remove "item" from URL.
With the below code and with custom post type url plugin http://wordpress.org/plugins/custom-post-type-permalinks/ my URL is:
Original URL : http://mywebsite/wp/item/america/mayer/
Want to change it to http://mywebsite/wp/america/mayer/
Without using htaccess
.
WordPress Code
function aitDirItemPostType() {
register_post_type( 'ait-dir-item',
array(
'labels' => array(
'name' => 'Items',
'singular_name' => 'Item',
'add_new' => 'Add new',
'add_new_item' => 'Add new item',
'edit_item' => 'Edit item',
'new_item' => 'New item',
'not_found' => 'No items found',
'not_found_in_trash' => 'No items found in Trash',
'menu_name' => 'Items',
),
'description' => 'Manipulating with items',
'public' => true,
'show_in_nav_menus' => true,
'supports' => array(
'title',
'thumbnail',
'author',
'editor',
'excerpt',
'comments',
),
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => AIT_FRAMEWORK_URL . '/CustomTypes/dir-item/dir-item.png',
'menu_position' => $GLOBALS['aitThemeCustomTypes']['dir-item'],
'has_archive' => true,
'query_var' => 'dir-item',
'rewrite' => array('slug' => 'item'),
'capability_type' => 'ait-dir-item',
'map_meta_cap' => true
)
);
aitDirItemTaxonomies();
flush_rewrite_rules(false);
}
add_action( 'init', 'aitDirItemPostType');
Share
Improve this question
edited May 15, 2014 at 12:56
Aravona
5851 gold badge5 silver badges19 bronze badges
asked May 15, 2014 at 11:55
JohanJohan
14 bronze badges
2
|
2 Answers
Reset to default 0You can omit the "base", by adding
rewrite => array(
slug => 'item',
with_front => false,
),
Don't forget to flush your rewrite rules after you changed that. The easiest way to do so it to simply visit the "admin > settings > permalinks" page.
If you need to add that to an already registered post type, then take a look at the internals of register_post_type()
and the available hooks and filters in its source Link to GitHub: Make use of the registered_post_type
action which comes with two arguments: $post_type
and $args
.
I think you have to set the slug
value to an empty string like ''
, deleting item
.
I think that @kaiser think that item
is a generic string for the posts, and he suggest to not prepend that string to your custom post type permalink. That's a good idea. But item
is the slug for the CPT, so that's why is not working
本文标签: pluginscustom url with custom post
版权声明:本文标题:plugins - custom url with custom post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298205a1930180.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'rewrite' => array('slug' => 'item'),
but you can't remove it. If you change it, remember you need to flush the rewrite rules afterwards by visiting the permalinks page in the administrative dashboard. – epilektric Commented May 15, 2014 at 13:12