How to change all permalink slugs on a custom post type to “post id” rather than “post title”

Today I needed to change the url slug of a custom post type from /cpt-slug/%post-title%/ to /cpt-slug/%post-id%/. There were thousands of solutions on the web explaining how to change the “cpt-slug” portion of the url, but I couldn’t find a simple solution to change the last part of the url. Well here it is!

The solution is:

  1. Install & activate Custom Post Type Permalinks plugin.
  2. Add 'cptp_permalink_structure' => '%post_id%' to the register_post_type function in functions.php.
add to functions
How to change all permalink slugs on a custom post type to "post id" rather than "post title" 2

That’s it!

Posted in

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to twitter.com/tobycryns and twitter.com/themightymo

Follow Toby's contributions on Github and WP.org.