Names of WordPress custom post types must be no longer than 20 characters
A quick WordPress tip regarding Custom Post Types: when giving a custom post type a name, make sure that its length is 20 characters or less, or weird things will happen.
I recently ran into this and spent way too much time trying to figure out why things weren’t working as expected. For some reason the “Publish” button on the “Add New” page for my custom post type was replaced by a “Submit for Review” button. Huh?
Instinctively I thought the problem was related to permissions, so I started messing about with users and permissions, but nothing helped. Simply pasting a basic example of a custom post type from the WordPress Codex page did work though, but my syntax was identical… almost.
It wasn’t until I changed the name (the first parameter that the register_post_type function takes) of my custom post type to something shorter that I started thinking that maybe there’s a limit, and indeed there is – 20 characters.
Yes, the maximum length of 20 characters is noted on the WordPress Codex page about custom post types, but it’s easy to miss that pretty vital piece of info. Maybe highlighting or emphasising it (as on the register_post_type page) would be a good idea :-).
I should also note that had I had WordPress debugging turned on I might have found the error quicker since you get a “Trying to get property of non-object” error when your custom post type name is too long. That doesn’t tell me about the 20 character limit but at least I wouldn’t have thought it was releated to user permissions.
Here’s hoping I can save someone else creating a custom post type without reading the WordPress Codex thoroughly enough some time and frustration.
- Previous post: @font-face tip: define font-weight and font-style to keep your CSS simple
- Next post: Safari for iOS needs a text size preference and text reflow