Hochman Consultants - Results Driven Internet Marketing

How to Automatically Generate Meta Descriptions

by Jonathan Hochman

Often large sites need to generate meta descriptions automatically because the labor cost would be excessive to write them for each page, such as when an ecommerce site has hundreds or thousands of dynamically generated pages. Unique meta descriptions help ensure that the search results contain a relevant hook to encourage the searchers to click through. Search engines may also use the meta descriptions and titles of pages to perform a quick check to see if pages are duplicates of one another. Having lots of pages with duplicate meta descriptions can hurt marketing and may also hurt the indexing and ranking of the pages.

Code Sample

The following code takes a text field, such as a product description, and generates a pretty good meta description.

/* PHP Function attempts to generate a meta description string at 
least 80 characters long, ending with a period. The output of 
this function should be html encoded with a function such as 
htmlspecialchars() before being inserted into a web page. */

function make_description($code) 
{
  $pagedesc=strip_tags($code);
  $padding = substr($pagedesc, 80);
  if ($padding === 0)
     return $pagedesc; 
  $length = strpos($padding, ".");
  if ($length === 0) 
      return $pagedesc; 
  return substr($pagedesc, 0, $length + 81); 
}

About the Author

After graduating from Yale with two degrees in Computer Science, Jonathan Hochman set up his own consulting company in 1990. He has been an Internet marketer since 1994.

For additional information, please contact Hochman Consultants.