Change permalink structure for custom post type


I have 2 custom post types: software and hardware. For SEO reasons I would like to have the permalinks of single software and hardware pages like:

But as default WordPress adds post-type slug on it like:

I’ve removed the slug with following script that makes a replacement of the string. Now the single page is reachable with both urls described above and Google search console find 2 pages with the exact same content which is not good for SEO.
Is it possible to change the complete structure of a permalink and get rid of custom post type slug?

register_post_type( 'hardware',
    array (
        'labels' => $labels,
        'has_archive' => true,
        'public' => true,
        'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' ),
        'taxonomies' => array( 'hardware-post_tag', 'hardware-category' ),
        'exclude_from_search' => false,
        'capability_type' => 'post',
        'rewrite' => array( 'slug' => 'hardware' ),

, 3ky 4 years 2020-02-18T08:38:32-05:00 0 Answers 98 views 0

Leave an answer