How-to: Shorten product title and description

Timo ASA 2 Pro, Tips 6 Comments

A frequently requested feature is to shorten an Amazon product’s title or description text because the original content is so long that it would destroy the page layout. This is possible with ASA 2’s powerful template syntax. You can use the template filters to customize placeholders in many different ways. To shorten a text, we can use the slice filter. With it you can extract a slice of a string.

Shorten Product Title …

To shorten the product title and be sure it will never have a length of more than 60 characters, we can use this placeholder syntax:

{{ Title|length > 60 ? Title|slice(0, 60) ~ '...' : Title }}

The code checks if the product title is longer than 60 characters. If so, it cuts the title after 60 characters and appends three dots. If the title is shorter, just the original title will be displayed. This placeholder syntax is used in the following template:
[asa2 tplid="12" country_code="US"]B00OQVZDJM[/asa2]

Price: $119.99
1 new from $119.992 used from $100.00
As of: 2017/10/16 12:30 pm

… and Description

The same procedure works for the product description text, which is represented by placeholder {{ EditorialReviewsContent }}. This placeholder syntax will limit the description text to a maximum of 250 characters:

{{ EditorialReviewsContent|length > 250 ? EditorialReviewsContent|slice(0, 250) ~ '...' : EditorialReviewsContent }}

This placeholder syntax is used in the following template where you can see a shortened product description:

Lonely Planet Berlin (Travel Guide) - Paperback (344 pages)
by Lonely Planet, Andrea Schulte-Peevers
Price: $20.50
You save: $4.49 (18 %)
16 new from $12.6740 used from $1.44
Lonely Planet: The world's leading travel guide publisher Lonely Planet Berlin is your passport to the most relevant, up-to-date advice on what to see and skip, and what hidden discoveries await you. Catch the lift to the Reichstag's dazzling glass d...

Search and replace parts of texts

When it comes to the modification of texts, another very useful filter is replace. It can be used like a search and replace tool. Let’s say you have a list of blu-ray movies and they all have “[Blu-ray]” in their titles. To get rid of that and just show the movie title, you can use the replace filter like so:
{{ Title|replace({'[Blu-ray]': ''}) }}

Permanent Custom Title

There is another option to customize a product’s title permanently. You can change the title of any ASA 2 Repo item like you would with any other WordPress post. Just open the edit page of a Repo item, change the title and click the “Update” button. From now on the new title will be used for placeholder {{ Title }}.

Changing ASA 2 Repo item title

Get ASA 2 Pro
Timo
Subscribe
Notify of
guest

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ataul Ghani
7 years ago

I love this plugin. I’ve share a review for amazon affiliate plugin for WordPress but didn’t added this one. Can i feature this plugin to my post? Please let me know. Thank You!

Timo
Admin
Reply to  Ataul Ghani
7 years ago

Sure. There even is an affiliate program for ASA 2 with which you might make some money recommending my plugin: https://getasa2.com/become-an-affiliate/

Paula
Paula
5 years ago

Where do you actually place the code in order to shorten the title? I want to use the Carousel option but the title is too long for each of the products. I have no idea how to shorten the title without knowing where to actually place the code you have indicated above.

Timo
Admin
Reply to  Paula
5 years ago

Hi Paula,

thank you for your feedback.

The examples in this article are intended for creating your own templates. The values in the curly braces are placeholders for ASA2 templates.
If you use the standard template, please try to include the option “title_length” in the shortcode, e.g. like this:

`[asa2_smart_collection cat_slug="coffee-maker" limit="10" title_length="50" tpl="Carousel" /]`

If 50 characters are still too many, you can of course reduce them.
I hope this helps you. If not, you are welcome to create a ticket (https://www.ifeelweb.de/support/) and I’ll take a look for myself.

Paula
Paula
Reply to  Timo
5 years ago

Awesome. The shortcode is all I needed. It works beautifully.

Timo
Admin
Reply to  Paula
5 years ago

Cool! Thanks for letting me know.