I have set up a custom post type called projects. When a project is viewed this is the URL its is on: http://example.com/blog/projects/project-number-one But I want it to display without /blog like this: http://example.com/projects/project-number-one
My permalink structure is: /blog/%postname%/
If I remove /blog from the permalink structure then the project URLs are correct: http://example.com/projects/project-number-one
But then my blogposts look like this (with out /blog): http://example.com/blog-post
What I wound like is my blog posts' ULRs to look like this: http://example.com/blog/blog-post And my projects to be like this: http://example.com/projects/project-number-one
// This is my custom post type code:
function custom_post_type_projects() {
$labels = array(
'name' => 'Projects',
'singular_name' => 'Project',
'menu_name' => 'Projects',
'name_admin_bar' => 'Projects',
'archives' => 'Projects',
'attributes' => 'Projects Attributes',
'parent_item_colon' => 'Parent Project:',
'all_items' => 'All Project pages',
'add_new_item' => 'Add New Project / Project Page',
'add_new' => 'Add New',
'new_item' => 'New Project / Project Page',
'edit_item' => 'Edit Project / Project Page',
'update_item' => 'Update Project / Project Page',
'view_item' => 'View Project / Project Page',
'view_items' => 'View Projects',
'search_items' => 'Search Project / Project Pages',
'not_found' => 'Not found',
'not_found_in_trash' => 'Not found in Trash',
'featured_image' => 'Featured Image',
'set_featured_image' => 'Set featured image',
'remove_featured_image' => 'Remove featured image',
'use_featured_image' => 'Use as featured image',
'insert_into_item' => 'Insert into Project page',
'uploaded_to_this_item' => 'Uploaded to this item',
'items_list' => 'Projects list',
'items_list_navigation' => 'Projects list navigation',
'filter_items_list' => 'Filter Projects list',
);
$args = array(
'label' => 'Project',
'description' => 'Projects',
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes', 'revisions', 'excerpt'),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-format-gallery',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => 'projects',
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'show_in_rest' => true
);
register_post_type( 'projects', $args );
}
add_action( 'init', 'custom_post_type_projects', 0 );