Amit

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 );

Last Update on:March 5th, 2023 at 5:19 pm


WordPress list categories with post count
Previous post