Returns as many characters as possible, starting from the beginning of a string and counting up to a delimiter, while staying within max_length. If the string is already within max_length, the function returns string exactly as it was passed in.

Always counts in the natural direction of the advertiser’s locale. For example, if the advertiser’s language is English, this function counts from left to right.


reduce_words(string, max_length, delimiter, [delimiter], ...)
Learn more about syntax for functions.


  • string: An inventory string attribute such as DESCRIPTION, or a static string surrounded by quotes such as "My great shoe store".
    Learn more about referring to inventory attributes.
  • max_length: the maximum number of characters in the output string. Can be any of the following:
    • 0 (zero).
    • A positive integer, such as 5.
    • An expression or inventory function that returns a positive number.
  • delimiter: A single character such as " " or a static string such as "store". If you specify more than one delimiter, the function uses the delimiter that yields the longest string fitting within max_length.


  • reduce_words("My great shoe store", 10, " ") returns "My great". To calculate this string, the function follows these steps:

    1. Finds the last instance of the delimiter (which is the space between "shoe" and "store").

    2. Counts backwards 10 characters to see if it has reached the beginning of the string.

    3. In this example, the function doesn't reach the beginning, so it moves to the previous instance of the delimiter, the space between "great" and "shoe", and counts backwards 10 characters.

    4. The function reaches the beginning of the string before finishing the count, so it returns everything preceding the delimiter.

  • reduce_words(DESCRIPTION, 15, " and"). If the inventory feed specifies "Low prices and wide selection" for the DESCRIPTION attribute, this function returns "Low prices". Note that the delimiter includes a space before "and". Without the space in the delimiter, the function would return "Low prices ".
  • reduce_words(DESCRIPTION, 15, " "). If the inventory feed specifies "Low prices" for the DESCRIPTION attribution, the function returns "Low prices".
Was this helpful?
How can we improve it?