15th July, 2021
How to remove custom post type slug from wordpress
First, you need to filter the permalink for your custom post type so that all published posts don’t have the slug in their URLs:
function ab_remove_cpt_slug( $post_link, $post ) {
if ( 'post_type' === $post->post_type && 'publish' === $post->post_status ) {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'ab_remove_cpt_slug', 10, 2 );