Page 1 of 1

Limit text when entering text in category meta description

Posted: Sun Jun 02, 2024 1:53 pm
by 14Steve14
Title sort of says it all really.

We are using 1.9.0. and wish to limit the text that is entered into the product meta description box when creating a product. Google limits this to 160 characters so we would like to make sure that all our required keywords are used in the first 160. I am aware that if the text is longer Google will only show the first 160, or make up its own text.

Is there a simple way of limiting these characters when creating products.

I can see that in the admin - actions - catalog - infoboxes - edit_category.php there is the following coede spo ids this somewhere where a limit can be added or is it somewhere else.

Code: Select all

$category_seo_description_string .= (new Textarea("categories_seo_description[{$l['languages_id']}]", ['id' => "cSeoDescription-{$l['code']}", 'cols' => '80', 'rows' => '10']))->set_text($l['categories_seo_description'] ?? '');
If its is not possible then we can reduce the size of the visible input area so that it matches the number but I was sort of looking for the correct way of doing it.

Re: Limit text when entering text in category meta description

Posted: Sun Jun 02, 2024 2:03 pm
by ecartz

Code: Select all

$category_seo_description_string .= (new Textarea("categories_seo_description[{$l['languages_id']}]", ['id' => "cSeoDescription-{$l['code']}", 'cols' => '80', 'rows' => '5', 'maxlength' => '160']))->set_text($l['categories_seo_description'] ?? '');
I also reduced the number of rows. That's not strictly necessary but saves some space.

Note that it may be better to limit the length on submission than in the HTML.

Code: Select all

      'categories_seo_description' => substr(Text::prepare($_POST['categories_seo_description'][$l['id']], 0, 160)),
or even at display time.

Re: Limit text when entering text in category meta description

Posted: Sun Jun 02, 2024 2:44 pm
by 14Steve14
@ecartz Many thanks for that. Seems to work like a charm. Hopefully will make our sites SEO better.