Change Slug Of Custom Post Type In WordPress

Here we learn how to change the slug of custom post type in WordPress,
If you want to change the slug you need to follow the below instruction,

1)  we need To add the below line in the custom post type,

'rewrite' => array( 'slug' => 'custom-post-type-slug', 'with_front' => false ),

2)  Now we use register_post_type_args filter and add the below code in functions.php file

add_filter( 'register_post_type_args', 'change_custom_post_type', 10, 2 );
function change_custom_post_type( $args, $post_type ) {

    if ( 'movie' === $post_type ) {
        $args['rewrite']['slug'] = 'pictures';
    }

    return $args;
}

after changes of the slug of the post you need to go settings->permalinks and refresh permalink.

Here the output will be display look like as below picture

Submit a Comment

Your email address will not be published. Required fields are marked *

Footer Logo

Subscribe

Select Categories