Skip Navigation

[Resolved] Types – custom post type – slug length limited to 20 characters

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to remove the 20 character limit on custom post type slugs.

Solution: This 20 character limit is imposed by WordPress and Toolset does not provide the capability to override that limit. Types registers custom post types using the standard WordPress function "register_post_type". Please see the register_post_type documentation link below.

If you just want to have longer slugs in the URLs for your CPT, you can use the Rewrite option in the post type editor to specify a different slug. The 20-character limit does not apply to the rewrite. I'm attaching a screenshot that shows where this option can be modified. This would result in posts with URLs like http://yoursite.com/this-is-a-long-slug-that-can-replace-your-short-cpt-slug/post-slug

Relevant Documentation: https://codex.wordpress.org/Function_Reference/register_post_type

This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by John Johansen 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#590897

I am trying to:
Create a slug value for a custom post type that is longer than 20 characters.

Link to a page where the issue can be seen:
Not applicable.

I expected to see:
Be able to enter a slug value longer than 20 characters, which was an issue addressed previously regarding posts.
Instead, I got:
Slug values for custom post types cannot be longer than 20 characters.

#591041
Screen Shot 2017-11-19 at 4.33.43 PM.png

If you're referring to the custom post type slug, this 20 character limit is imposed by WordPress and Toolset does not provide the capability to override that limit. Types registers custom post types using the standard WordPress function "register_post_type". Please see the register_post_type documentation here:
https://codex.wordpress.org/Function_Reference/register_post_type

$post_type
(string) (required) Post type. (max. 20 characters, cannot contain capital letters or spaces)

Furthermore, the database schema for post_type is limited to 20 Bytes by WordPress. See wp-admin/includes/schema.php:

TABLE $wpdb->posts (
  ...
  post_type varchar(20) NOT NULL default 'post',
  ...
)

May I ask why you need longer CPT slugs? There might be another way to achieve what you're looking for. For example, if you just want to have longer slugs in the URLs for your CPT, you can use the Rewrite option in the post type editor to specify a different slug. The 20-character limit does not apply to the rewrite. I'm attaching a screenshot that shows where this option can be modified. This would result in posts with URLs like http://yoursite.com/this-is-a-long-slug-that-can-replace-your-short-cpt-slug/post-slug

#591060

Christian:
Thanks for the clarification.
In order to prevent naming conflict errors among all of the slug values across the scope of the site, I want to employ a structured naming convention for them. The 20-character limit simply imposes a constraint that will require an exception to the convention for custom post types.
That said, I'm not really too concerned about the length of the URLs.