How to get dashes in post type/taxonomy slugs for URL SEO purposes

Custom Post Type UI version 1.3.0 introduced JavaScript that enforces underscore characters in slugs. When a user tried to type a dash in the slug field, it gets automatically switched to an underscore. We have always tried to use smart defaults in CPTUI for our users. The slug field is another place where we continue that.

In WordPress core, there are many places that allow customization via post type slugs. For those to work properly, they need to have underscores, and not dashes. This is one reason we decided to take this route.

One challenge from forcing underscores is that search engines favor URLs that use hyphens. It is not an insurmountable challenge, and is actually quite easy to resolve.

For years, Custom Post Type UI has provided post type and taxonomy custom rewrite slug fields. With these fields you can change the post type or taxonomy to show hyphens instead of underscores. Having a post type of my_post_type remains, but when used in URLs, it will appear as my-post-type. The same applies for the taxonomies.

With this, you can have the best of both worlds.