How can I change Item’s slug and slug of other custom post types?

Updated: July 29, 2016

If you want to change the slug or name of item that appears in the website url (e.g. http://domain.xy/item/some-item) or some other keyword for other post types and taxonomies you can make it very easily:

Change slug from plugin files

Item slug in URL

In the file of Ait Toolkit plugin ./wp-content/plugins/ait-toolkit/cpts/item/@item.cpt.php you have to add new part rewrite as you can see on following image.

Change Item Post Slug

Item slug in breadcrumbs

If you want to change also the slug which appears in the breadcrumbs you must change the name parameter of labels section:

Change Item Post Name

new-item-breadcrumb-slug

Taxonomy slug

Exactly same way you can change the slugs for categories, locations or any taxonomies. Taxonomy of the post type is specified in the same file ./wp-content/plugins/ait-toolkit/cpts/item/@item.cpt.php

Change Taxonomy Slug

Important: If you can’t access any item or category after this modification and the only you get is 404 – Nothing Found page, please follow the instruction in this article. Keep in mind that this modifications will be replaced by original files each time the Ait Toolkit plugin is updated!

Change slug from functions.php

Following example is used for advanced users or developers, we do not guarantee broken funkcionality using own incorrectly implemented code example.

If you are using child theme, better way to change slugs of post types or taxonomies (archive pages) may be using of filters inside your functions.php file in child theme:

change_slug_function_child_theme

/*
CHANGE SLUGS OF CUSTOM POST TYPES
*/
function change_post_types_slug( $args, $post_type ) {
   
   /*item post type slug*/   
   if ( 'ait-item' === $post_type ) {
      $args['rewrite']['slug'] = 'my-new-item-slug';
   }

   /*standard event post type slug*/   
   if ( 'ait-event' === $post_type ) {
      $args['rewrite']['slug'] = 'my-new-event-slug';
   }

   /*portfolio post type slug*/   
   if ( 'ait-portfolio-item' === $post_type ) {
      $args['rewrite']['slug'] = 'my-new-portfolio-slug';
   }

   /*event pro post type slug, available with Events Pro plugin*/
   if ( 'ait-event-pro' === $post_type ) {
      $args['rewrite']['slug'] = 'my-new-eventpro-slug';
   }

   return $args;
}
add_filter( 'register_post_type_args', 'change_post_types_slug', 10, 2 );


/*
CHANGE SLUGS OF TAXONOMIES, slugs used for archive pages
*/
function change_taxonomies_slug( $args, $taxonomy ) {
   
   /*item category*/
   if ( 'ait-items' === $taxonomy ) {
      $args['rewrite']['slug'] = 'my-new-category-slug';
   }

   /*item and event pro locations*/
   if ( 'ait-locations' === $taxonomy ) {
      $args['rewrite']['slug'] = 'my-new-location-slug';
   }

   /*item and event pro locations*/
   if ( 'ait-portfolios' === $taxonomy ) {
      $args['rewrite']['slug'] = 'my-new-portfolios-slug';
   }

   /*event pro category, available with Events Pro plugin*/
   if ( 'ait-events-pro' === $taxonomy ) {
      $args['rewrite']['slug'] = 'udalosti';
   }
   
   return $args;
}
add_filter( 'register_taxonomy_args', 'change_taxonomies_slug', 10, 2 );

Similar way you can change other parameters used for registered post type.