Home > Shopify Development > Liquid truncatewords: How to Cut Down String to Number of Words

Liquid truncatewords: How to Cut Down String to Number of Words in Shopify

Sam Nguyen
Sam Updated: May 23, 2024

Share:

Drive 20-40% of your revenue with Avada
avada email marketing

Do you feel tired of lengthy product descriptions overwhelming your Shopify store’s design? Utilize the power of Liquid’s truncate word filter to effortlessly trim down text, create enticing previews, and enhance your store’s overall user experience. Read on to discover how this simple yet powerful tool can transform your product displays and boost engagement!

How to Cut Down String to Number of Words in Shopify

About truncatewords

As the definition of the Truncation in the last article Liquid truncate: How to Cut Down String to Number of Characters, we mentioned that Truncation is considered as a cutting or removing tool. Through that tutorial, online sellers totally enable cutting down their strings into the number of words they want by truncation. In addition, the users can use the Truncate to make a string shorter. For this article How to Cut Down String to Number of Words in Shopify will bring the users simple steps to cut their strings with the expected number of words.

The way to cut down string to number of words

Step 1: Input

Input

{{ "Ground control to Major Tom." | truncatewords: 3 }}

Step 2: Output

Output

Ground control to...

Custom ellipsis (Click here)

There is an ellipsis (…) by default but the Shopify store owners can modify it with different sequences. The second parameter will take optionally by truncate. In addition, the length of this second parameter takes which is an optional count against the number of characters specified by the first parameter. For instance, the Shopify store owners want to truncate a string to exactly 10 characters, they could use a 3-character ellipsis and then the first parameter of truncate will be used in 3 characters.

The input of this case is:
Input

{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}


Output

Ground control to--

No ellipsis (Click here)

Try to avoid showing trailing characters, the second parameter can pass a blank string.

Input

{{ "Ground control to Major Tom." | truncatewords: 3, "" }}

Output

Ground control to

How to Use Liquid truncatewords in Shopify

  • Identify the string: Locate the text you want to shorten within your Liquid code (e.g., product.description, blog.content).
  • Apply the filter: Use the following syntax: .
  • Customize (optional): If you want to change the default ellipsis (…), add a second argument: .
  • Save and preview: Save your changes and preview the page to see the truncated string.

Why truncation is necessary

Truncation is a way to shorten text so that it fits in a specific area, such as a product listing page, blog post summary, or social media post. This is important for improving the readability and layout of your Shopify store. Long blocks of text can be overwhelming for visitors, and truncation can help make your content more scannable and digestible.

What to do with the truncated text on Shopify

  • Include an ellipsis (…) to indicate that the text has been truncated. This is a common convention that most users understand.
  • Add a “Read more” link to direct visitors to the full text. This is a good option for longer pieces of content, such as product descriptions or blog posts.
  • Use a tooltip to display the full text on hover. This can be a helpful way to provide more information without cluttering up your page.

When Shopify store owner may want to truncate text

  • Product descriptions: Truncate product descriptions to fit on the product listing page, encouraging visitors to click through to read the full description.
  • Blog post summaries: Truncate blog post summaries to display on the blog homepage or in social media feeds, enticing readers to click through to read the full post.
  • Meta descriptions: Truncate meta descriptions to fit within the character limit for search engine results pages (SERPs), ensuring that your listings are informative and clickable.
  • Social media posts: Truncate text to fit within the character limit for specific social media platforms, such as Twitter or Facebook.

Conclusion

In this article How to Cut Down String to Number of Words in Shopify, we hope that the Shopify store owners enable helping to cut down the string which has the number of words in Shopify. Including the simple steps, online sellers can do it by themselves. Moreover, in this article, the Shopify sellers also have more knowledge about Liquidity in the Shopify. In addition, we hope that online merchants to have more understanding of Shopify as well as Liquid through our chain of articles like the following list:


Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

Stay in the know

Get special offers on the latest news from AVADA.