Remove slug from custom post type

This has been asked many times but each solution I’ve tried doesn’t work for me – I’m trying to remove the slug of a custom post type. I’ve tried setting

 'with_front' => false,

but this also doesn’t work for me. With this suggestion, it removes the slug in the permalink within the admin area (in my case ‘locations’) but then visiting the new link I get a 404. I’ve tried flushing permalinks and this doesn’t help. However, I can still access the post by visiting /locations/post-name.

Read More

How can I solve this? Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. Try following code

    function remove_custom_post_type_slug( $post_link, $post, $leavename ) {
    
        $post_link = str_replace( '/locations/', '/', $post_link );
    
        return $post_link;
    }
    add_filter( 'post_type_link', 'remove_custom_post_type_slug', 10, 3 );
    

    See Reference