Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Auto Generated Meta Description Length Rate Topic   - - - - -

 
  • The Tool
  • Been Here Way Too Long Member
  • Members
  • Join Date: 30-Mar 07
  • 3693 posts

Posted 14 June 2016 - 08:32 PM #1

I have been getting notices from search engines that my meta description length was too long.  Upon investigation, I found that my meta descriptions were anywhere from 250-300 characters in length.  Most suggest that the length should be 155 or less.

 

CSC has $max_letters = 250 which is obviously too much and I am not sure why some of my meta descriptions were more than 250.  After some testing, I found that $max_letters = 130 puts me just under 155 while $max_letters = 140 puts me just over 155.  I stuck with 130 to be on the safe side.

 

/app/functions/fn.common.php

/**
 * Return cleaned text string (for meta description use)
 *
 * @param string $html - html code to generate description from
 * @param int $max_letters - maximum letters in description
 * @return string - cleaned text
 */
function fn_generate_meta_description($html, $max_letters = 130)
{
    $meta = array();
    if (!empty($html)) {
        $html = str_replace(' ', ' ', $html);
        $html = str_replace(array("\r\n", "\n", "\r"), ' ', html_entity_decode(trim($html), ENT_QUOTES, 'UTF-8'));
        $html = preg_replace('/\<br(\s*)?\/?\>/i', " ", $html);
        $html = preg_replace('|<style[^>]*>.*?</style>|i', '', $html);
        $html = strip_tags($html);
        $html = str_replace(array('.', ',', ':', ';', '`', '"', '~', '\'', '(', ')'), ' ', $html);
        $html = preg_replace('/\s+/', ' ', $html);
        $html = explode(' ', $html);
        $letters_count = 0;
        foreach ($html as $k => $v) {
            $letters_count += fn_strlen($v);
            if ($letters_count <= $max_letters) {
                $meta[] = $v;
            } else {
                break;
            }
        }
    }

    return implode(' ', $meta);
}


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18489 posts

Posted 16 June 2016 - 12:57 PM #2

This function calculates $letters_count incorrectly. Instead of the following line:

$letters_count += fn_strlen($v);

there should be something like this (add 1 character for the space between words):

$letters_count += fn_strlen($v) + (empty($meta) ? 0 : 1);

because of this one (add spaces between words):

return implode(' ', $meta);

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • The Tool
  • Been Here Way Too Long Member
  • Members
  • Join Date: 30-Mar 07
  • 3693 posts

Posted 18 June 2016 - 04:41 AM #3

Thanks eCom.  I didn't have time to look into finding out why there was a miscount but you are correct that it wasn't counting the spaces.  Your solution gives me more of a precise count so that I can use $max_letters = 155 now.

 

Edit:  I just wanted to let everyone else reading this that Google was not reporting my meta descriptions as being too long with the original code (not sure that Google really cares since I have seen various versions of my descriptions in Google's search) but Bing and some others were.



 
  • Mongoose
  • Senior Member
  • Members
  • Join Date: 08-Mar 13
  • 968 posts

Posted 28 August 2016 - 09:46 PM #4

@TheTool

 

What does this code do for you that you posted exactly ? Does it limit the amount of characters you can add in the meta tags of products, categories and pages ?


CS Cart Evangelist - running CS Cart 4.7.4 in three domains


 
  • The Tool
  • Been Here Way Too Long Member
  • Members
  • Join Date: 30-Mar 07
  • 3693 posts

Posted 29 August 2016 - 11:38 AM #5

@TheTool

 

What does this code do for you that you posted exactly ? Does it limit the amount of characters you can add in the meta tags of products, categories and pages ?

 

This is based on the auto generated meta description meaning what the system generates if you do not input a meta description yourself.



 
  • johnbol1
  • Never Re
  • Members
  • Join Date: 23-Feb 10
  • 4395 posts

Posted 05 June 2018 - 08:50 PM #6

Can anyone tell me what the meta description length limit is now in v4.7, 4.5

 

Thanks


Custom printed hi visibility clothing sale the UK's online hivis safety shop
v4.5.2


 
  • The Tool
  • Been Here Way Too Long Member
  • Members
  • Join Date: 30-Mar 07
  • 3693 posts

Posted 06 June 2018 - 01:48 AM #7

Can anyone tell me what the meta description length limit is now in v4.7, 4.5

 

Thanks

 

It hasn't changed.  It is still 250.



 
  • johnbol1
  • Never Re
  • Members
  • Join Date: 23-Feb 10
  • 4395 posts

Posted 06 June 2018 - 09:11 AM #8

Found it, changed in here to 320

 

https://prnt.sc/jricio


Custom printed hi visibility clothing sale the UK's online hivis safety shop
v4.5.2


 
  • The Tool
  • Been Here Way Too Long Member
  • Members
  • Join Date: 30-Mar 07
  • 3693 posts

Posted 06 June 2018 - 12:05 PM #9

Oh, I thought you were referring to the auto generated meta description which is what the thread is discussing.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 18489 posts

Posted 06 June 2018 - 01:17 PM #10

Found it, changed in here to 320

 

https://prnt.sc/jricio

 

Please also make the same changes in cscart_ult_product_descriptions table


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • johnbol1
  • Never Re
  • Members
  • Join Date: 23-Feb 10
  • 4395 posts

Posted 06 June 2018 - 03:17 PM #11

Oh, I thought you were referring to the auto generated meta description which is what the thread is discussing.

My Mistake, I got the 2 confused

 

@ecomlabs, will do thanks


Custom printed hi visibility clothing sale the UK's online hivis safety shop
v4.5.2