Support Forum
Support › MB Custom Post Type › Remove slugs from multiple custom pageResolved
Hi !
I'm working on create multiple custom page with different setting.
My issue is with the slug, I want them all to look like that domain.com/PAGE_NAME
instead of domain.com/TYPE_OF_PAGE/PAGE_NAME
.
I'm trying to do so using 'rewrite' => array('slug' => '/','with_front' => true),
but when I do that I'm no longer able to display other type of page. I refresh the permalinks and all but only the last type of page with this rewrite is displayed correctly, I've got 404 on the rest.
Even the WordPress "page" type of post won't work anymore.
Here is an example with 2 custom type of pages called boom
and biim
.
public function page_register_post_type_biim() {
$args = [
'label' => esc_html__( 'pages biim', $this->current_theme ),
'labels' => array(
'menu_name' => esc_html__( 'papernest', $this->current_theme ),
'name_admin_bar' => esc_html__( 'page', $this->current_theme ),
'add_new' => esc_html__( 'Add new', $this->current_theme ),
'add_new_item' => esc_html__( 'Add new page', $this->current_theme ),
'new_item' => esc_html__( 'New page', $this->current_theme ),
'edit_item' => esc_html__( 'Edit page', $this->current_theme ),
'view_item' => esc_html__( 'View page', $this->current_theme ),
'update_item' => esc_html__( 'Update page', $this->current_theme ),
'all_items' => esc_html__( 'Pages', $this->current_theme ),
'search_items' => esc_html__( 'Search pages', $this->current_theme ),
'parent_item_colon' => esc_html__( 'Parent page', $this->current_theme ),
'not_found' => esc_html__( 'No pages found', $this->current_theme ),
'not_found_in_trash' => esc_html__( 'No pages found in Trash', $this->current_theme ),
'name' => esc_html__( 'pages', $this->current_theme ),
'singular_name' => esc_html__( 'page', $this->current_theme ),
),
'public' => true,
'description' => 'Test',
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'show_in_rest' => false,
'menu_position' => 2,
'show_in_menu' => 'papernest',
'capability_type' => 'page',
'hierarchical' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite_no_front' => true,
'supports' => array(
'title',
),
'rewrite' => array('slug' => '/','with_front' => false),
];
register_post_type( 'biim', $args );
}
public function page_register_post_type_boom() {
$args = [
'label' => esc_html__( 'pages boom', $this->current_theme ),
'labels' => array(
'menu_name' => esc_html__( 'papernest', $this->current_theme ),
'name_admin_bar' => esc_html__( 'page', $this->current_theme ),
'add_new' => esc_html__( 'Add new', $this->current_theme ),
'add_new_item' => esc_html__( 'Add new page', $this->current_theme ),
'new_item' => esc_html__( 'New page', $this->current_theme ),
'edit_item' => esc_html__( 'Edit page', $this->current_theme ),
'view_item' => esc_html__( 'View page', $this->current_theme ),
'update_item' => esc_html__( 'Update page', $this->current_theme ),
'all_items' => esc_html__( 'Pages', $this->current_theme ),
'search_items' => esc_html__( 'Search pages', $this->current_theme ),
'parent_item_colon' => esc_html__( 'Parent page', $this->current_theme ),
'not_found' => esc_html__( 'No pages found', $this->current_theme ),
'not_found_in_trash' => esc_html__( 'No pages found in Trash', $this->current_theme ),
'name' => esc_html__( 'pages', $this->current_theme ),
'singular_name' => esc_html__( 'page', $this->current_theme ),
),
'public' => true,
'description' => 'Test',
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'show_in_rest' => false,
'menu_position' => 2,
'show_in_menu' => 'papernest',
'capability_type' => 'page',
'hierarchical' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite_no_front' => true,
'supports' => array(
'title',
),
'rewrite' => array('slug' => '/','with_front' => true),
];
register_post_type( 'boom', $args );
}
Apart from the name of the post, they are 100% identical but only Boom
works because it is my last declaration.
Do you happened to know what this is about ?
I tried plugins but nothing seems to work.
Thank in advance 🙂
Hi Virgile,
You have to use the code to remove post type slug from the permalink. Please follow these topics for more information
https://wordpress.org/support/topic/removing-slug-in-url-from-custom-post-type/
https://stackoverflow.com/questions/41230665/how-to-remove-taxonomy-slug-from-custom-post-type-url