Limit text when entering text in category meta description

Open to all! Ask other shopowners for help.
Post Reply
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Limit text when entering text in category meta description

Post 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.


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Limit text when entering text in category meta description

Post 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.
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Limit text when entering text in category meta description

Post by 14Steve14 »

@ecartz Many thanks for that. Seems to work like a charm. Hopefully will make our sites SEO better.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply