Custom post type and page share the same URL

So you’ve accidentally named your CPT and page URL (the slug) the same? Here are a few solutions on how you could fix it.

Disable your CPT's archive

One way to fix this is by disabling your custom post type’s archive, by changing has_archives to false when you come to register your CPT.

Please, see the example below:

function custom_post_type_function() {
    $labels = array(
        'name' => 'Post Types',
        'singular_name' => 'Post Type',
        'menu_name' => 'Post Types',
        'name_admin_bar' => 'Post Type',
        'add_new' => 'Add Post Type',
        'add_new_item' => 'Add New Post Type',
        'new_item' => 'New Post Type',
        'edit_item' => 'Edit Post Type',
        'view_item' => 'View Post Type',
        'all_items' => 'All Post Types',
        'search_items' => 'Search Post Types',
        'parent_item_colon' => 'Parent Post Type',
        'not_found' => 'No Post Types Found.',
        'not_found_in_trash' => 'No Post Types Found In Trash.'
    );
    $args = array(
        'labels' => $labels,
        'description' => 'Custom Post Type Description.',
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'custom-post-type-slug' ),
        'capability_type' => 'post',
        'menu_icon' => 'dashicons-media-interactive',
        'has_archive' => false,
        'hierarchical' => true,
        'menu_position' => null,
        'exclude_from_search' => false,
        'supports' => array( 'title', 'editor', 'thumbnail' )
    );
    register_post_type( 'custom_post_type_name', $args );
}

add_action( 'init', 'custom_post_type_function' );

Note, after you’ve done this, you may need to refresh your permalinks.

Change your page's URL

This one’s a simple fix and allows you to keep your CPT’s archive.

Simply, change your page’s URL (the slug) through WordPress accordingly.

For example, if your CPT archive and page share the same URL of example.com/services/, you could change your page’s slug. to show the URL as example.com/our-services/.

Change the custom post type's URL

This one’s a little more tricky as it involves a few more steps. However, here they are:

  1. Create a new CPT using the new slug.
  2. Use the Post Type Switcher plugin, to switch posts from the old CPT to the new.
  3. Delete your old CPT and refresh your permalinks.