You are here:  » How To Limit Length of Titles?


How To Limit Length of Titles?

Submitted by ItsDavid on Sat, 2017-01-28 17:03 in

Most of my feeds have titles (Names) that are way to long which also produce extremely long URL's.

How can i limit the length of titles and URL's?

for instance here is an example of one of my URL's after /product/

activesmart-series-rs36a72jc1-36-inch-built-in-french-door-refrigerator-with-16.8-cu.-ft.-capacity-activesmart-technology-adjustable-spill-proof-glass-shelves-gallon-door-bin-storage-humidity-controlled-drawers-internal-ice-maker-energy-star-and-frost.html

I would also like to be able to prevent words and strings of words from being used as the URL such as "with-16.8-cu.-ft.-"

How can i strip these things from the URL to make them cleaner and more SEO friendly?

Thanks in advance.

Submitted by support on Mon, 2017-01-30 09:00

Hi David,

To remove unwanted text from the name, first add the new Search and Replace RegExp filter from this thread.

Then to remove "16.8 cu ft." as in your example, use a Search expression of:

/\b(.*) cu ft\./

(\b matches any word boundary character e.g. beginning of line, end of line, space, punctuation etc., and the \ in-front of "." is to "escape" it and match a literal "." since otherwise, "." is the any character wildcard match)

...and leave Replace empty.

Then to shorten the URLs, you can use the tapestry_substr() function on the normalised_name field at import time since the URL is constructed from that field (rather than `name`). To do this, edit includes/admin.php and look for the following code at line 469:

    $searchName = tapestry_search($normalisedName);

...and REPLACE with:

    $searchName = tapestry_search($normalisedName);
    $normalisedName = tapestry_substr($normalisedName,100);

And then the following code at line 483:

    $dupe_key .= tapestry_mb_strtolower($searchName);

...and REPLACE with:

    $dupe_key .= tapestry_mb_strtolower($normalisedName);

That would limit the URL length to the nearest whole word after 100 characters - adjust in the first replacement as required. The changes will be applied after the next full import.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ItsDavid on Wed, 2017-02-01 02:06

Hi David,

I don't know regular expression so i was wondering how would i know what to use to remove certain things without needing to bug you every time i want to remove something?

Submitted by support on Wed, 2017-02-01 10:08

Hello David,

There is a brief introduction to Regular Expressions and a link to a crib sheet in the Product Mapping by RegExp documentation which you can find here.

If ever you're not sure at all of course, just let me know...

Cheers,
David.
--
PriceTapestry.com