Change Category Slug and Category URL for a Custom Post Type

I recently started working with a new theme called EvenTalk and while it has lots of great pre-built styles and custom post types, they have affixed their theme name to many of the post types and taxonomies within the theme. For example, it has a custom post type called “Speakers” which has a taxonomy for categories. When you want to display the category archive for a specific category, the URL looks like this:

In the theme options there is a spot to change this slug, but it doesn’t work. When I tried to dive into the core theme files, I couldn’t find where it was being set. So here is a simple function you can add to functions.php in your child theme to overwrite the category slug for a custom post type.

  1. In WordPress, click on Appearance -> Theme Editor
  2. On the right side of the screen click on functions.php
  3. Paste the following code:

    function fix_cat_slug( $taxonomy, $object_type, $args ){
        if( 'old-slug' == $taxonomy ){
            remove_action( current_action(), __FUNCTION__ );
            $args['rewrite'] = array( 'slug' => 'new-slug' );
            register_taxonomy( $taxonomy, $object_type, $args );
    add_action( 'registered_taxonomy', 'fix_cat_slug', 10, 3 );

  4. Replace old-slug with the slug of the category you want to change. Replace new-slug with what you want to change it to. In my case, I ended up doing this:
  5. Click on the blue “Update File” button at the bottom of the screen.
  6. In the WordPress side menu click on Settings -> Permalinks and then once it loads, click on the “Save Changes” button.


Related Posts

Leave a Reply

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

Captcha loading...