# Change the URL Slug of Any Post Type

> Changes the URL base of a post type registered by a theme or plugin, for example from /portfolio/ to /work/, including its archive.

- Type: PHP
- Runs: Run everywhere
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: permalinks, slugs, custom-post-types
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/change-post-type-slug/

## Code

```php
// Post type => new slug.
$wpide_new_slugs = array(
    'portfolio' => 'work',
);

add_filter( 'register_post_type_args', function ( $args, $post_type ) use ( $wpide_new_slugs ) {
    if ( ! isset( $wpide_new_slugs[ $post_type ] ) ) {
        return $args;
    }

    $args['rewrite'] = array_merge( is_array( $args['rewrite'] ?? null ) ? $args['rewrite'] : array(), array( 'slug' => $wpide_new_slugs[ $post_type ] ) );

    if ( ! empty( $args['has_archive'] ) ) {
        $args['has_archive'] = $wpide_new_slugs[ $post_type ];
    }

    return $args;
}, 10, 2 );
```

## Notes

Visit Settings > Permalinks once afterwards, and redirect the old URLs if the site is already indexed.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Change the URL Slug of Any Post Type" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
