Google did not fix my problem so..

Anyone here know how to increase the character limit for woocommerce product attribute slug, default it has a limit of 28 characters (max 32 in database) i need max 40.(tried to increase to max 128).

I’m testing a local site where product information comes from imported xml files, sometimes certain attribute names are just longer than 28 characters..

Changed the corresponding column in database from vachar(32) to varchar(128),

Tried to change the values in wc-attribute-functions.php, and changed 28 to 128, but that didnt help..

// Validate slug.
if ( strlen( $slug ) >= 40 ) {
    /* translators: %s: attribute slug */
    return new WP_Error( ‘invalid_product_attribute_slug_too_long’, sprintf( __( ‘Slug “%s” is too long (40 characters max). Shorten it, please.’, ‘woocommerce’ ), $slug ), array( ‘status’ => 400 ) );

By now i am able to input a longer Attribute slug , but still get an error when saving..


This is the error i get when trying to add a term to the test attribute ( with longer name)

enter image description here

here you can see i am able to create an attribute with a slug of 38 characters, however when i look in the mysql database in the "products_term_taxonomy" table, it does not show up there,

enter image description here

After changing 32 character limit to 128 in file taxonomy.php,now i can add terms to attribute.

enter image description here

And now visible also in database,

enter image description here

  • "but still get an error when saving" - What's the error? A client-side validation error, or an error generated by WordPress, or a database error passed back through WordPress, or something else?
    – Rup
    Aug 28, 2019 at 11:40
  • Updated original question with error, as response to Rup Aug 28, 2019 at 11:58
  • Are these slugs used as taxonomies too then? There is a 32-character limit in register_taxonomy you might be running into. (That isn't AFAICS the code that makes new records though.) If not, I'd probably add trace to taxonomy_exists() and get_taxonomy() to see what the invalid value is.
    – Rup
    Aug 28, 2019 at 12:07
  • Yes after changing , the 32-character limit to 128 in taxonomy.php as you said, now i can add terms to longer attribute names, no more error and it shows up in the database, will update my question with screens .. Aug 28, 2019 at 12:39
  • Great! Changing taxonomy.php is a core patch though, and in general that's frowned upon as it will get lost in an automatic update. I don't see anything you could hook into to change this limit otherwise though.
    – Rup
    Aug 28, 2019 at 13:48

4 Answers 4


There is a solution for this.

  1. Manually create the long name attribute in "Product Attributes" page, and use a short slug name here. In the product import section there is no "attribute slug" in the Column Headers(Or maybe there is one but not used by WooCommerce by default).

    Like so

    enter image description here

    1. Then you can import from CSV files now. No need to change any code.

    Like so enter image description here

    enter image description here

    Hope this helps you.


As discussed in the comments, the problem is that these slugs are also used as taxonomy names and there's a 32-character limit on taxonomy names in WordPress core. From register_taxonomy():

if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) {
    _doing_it_wrong( __FUNCTION__,
        __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2.0' );
    return new WP_Error( 'taxonomy_length_invalid',
        __( 'Taxonomy names must be between 1 and 32 characters in length.' ) );

We can't see any way to override this limit without patching core.


Why do you need a long attribute slug? Need a longer attribute name?

You can solve it like this:

add_filter( 'sanitize_taxonomy_name', function( $urldecode, $taxonomy ) {
    $urldecode = mb_substr($urldecode, 0, 26, 'utf-8');
    return $urldecode;
}, 10, 2 );

WooCommerce will be able to save attributes with long names (more than 28 characters) from the admin panel and more!

  • Is this assuming that longer slug names will always have a unique first 26 characters?
    – Rup
    Dec 14, 2020 at 16:49

I fixed the issue by doing following actions.

  1. Upload your import_file.csv to Google Sheets.
  2. Search and Replace any long suspected attribute names to smth else or shorten.
  3. Download the file and try reimporting again. It should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.