Sometimes, you may want to change the URL slug of a custom post type to better reflect your site’s content or improve SEO. If the custom post type is registered by a plugin or the parent theme, you can easily override the slug by adding a function in your child theme.
In this tutorial, we’ll walk you through the steps to change the slug of a custom post type when you already know the existing slug.
Step 1: Determine the Current Slug
Before making any changes, ensure you know the current slug of the custom post type. This slug is part of the URL when you view a post of that type. For example, if the current URL is https://yourdomain.com/old-slug/post-name/, then old-slug is the slug you want to change. Or you can check it in your WP Dashboard by hovering over the post type menu.

Step 2: Add the Function to Your Child Theme
To change the slug, you’ll need to add a function to your child theme’s functions.php file. This function will use WordPress hooks to modify the existing custom post type’s rewrite rules.
- Open the
functions.phpfile in your child theme. If you don’t have afunctions.phpfile in your child theme, create one in your child theme directory. - Add the following function to modify the post type slug:
function change_post_type_slug() { // Get the global WordPress variable for post types global $wp_post_types; // Check if the post type exists before trying to modify it if (isset($wp_post_types['your_post_type_slug'])) { // Get the post type object $post_type = $wp_post_types['your_post_type_slug']; // Modify the slug $post_type->rewrite['slug'] = 'new-slug'; // Ensure the rewrite rules are applied correctly add_action('init', 'flush_rewrite_rules', 20); } } add_action('init', 'change_post_type_slug', 20);Replace
'your_post_type_slug'with the actual slug of the post type you want to change and'new-slug'with the new slug you want to use. - Save the
functions.phpfile after adding the function.
Step 3: Flush Rewrite Rules
To ensure the new slug is applied, you need to flush the rewrite rules in WordPress.
- Go to Permalinks Settings: In your WordPress dashboard, navigate to
Settings > Permalinks. - Save Changes: Scroll down and click the
Save Changesbutton. You don’t need to change any settings; just saving will flush the rewrite rules.
Step 4: Verify the New Slug
Now, you can check to ensure the slug has been updated successfully.
- View a Post: Navigate to a post of the custom post type you modified.
- Check the URL: The URL should now reflect the new slug, e.g.,
https://yourdomain.com/new-slug/post-name/.
With just a few lines of code added to your child theme, you can easily change the slug of any custom post type, whether it’s part of a plugin or the parent theme. This method ensures your customizations persist even when the parent theme or plugin is updated.