WordPress custom post type name length longer than 20 characters

WordPress is standard using a max of 20 characters for the custom post type name. You can add the code for a new custom post type in your functions.php but if the name is longer than 20 characters WordPress doesn’t accept it.

I’ve searched for it and found the solution to get a custom post type with a name longer than 20 characters:

  1. Open in /wp-includes the post.php file and search for the following line:
    if ( strlen( $post_type ) > 20 )
    return new WP_Error( ‘post_type_too_long’, __( ‘Post types cannot exceed 20 characters in length’ ) );
  2. Change this line to: (I took 50 characters in my example)
    if ( strlen( $post_type ) > 50 )
    return new WP_Error( ‘post_type_too_long’, __( ‘Post types cannot exceed 50 characters in length’ ) );
  3. Then open your database and edit the wp_posts > post_type column from 20 characters to 50 characters.

Remember that if you update WordPress you need to do these steps every time.

That’s it!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s