How to Write Meta Descriptions (Code Sample Included)

Ranking in search is only half the battle.  To obtain all the potential traffic, you need to know how to write meta descriptions that make your listings stand out and appeal to searchers.  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.  While it is best to custom craft meta descriptions by hand, this is not always possible.  We recommend having a method in place to generate meta descriptions automatically when then webmaster has not written them.  Google in particular takes the meta description tag as a recommendation.  If Google feels that other text on the page would be a better description for the search results, Google will disregard the meta description and use that other text instead.

Large sites should usually generate meta descriptions automatically because the time to write a meta description for all the pages could be excessive. When an eCommerce site has hundreds or thousands of dynamically generated pages, it often makes sense to dynamically generate meta descriptions.  Sometimes the best way to create a meta description is to create a template and perform substitution, such as:

<meta name="description" 
content="Buy {ProductName} ({PartNumber}) for less at Free shipping."/>

You would use the appropriate syntax and variables for your CMS to replace {ProductName} and {PartNumber} with dynamic values.

When this simple approach results in unappealing or redundant meta descriptions, or just can’t be implemented easily, a more sophisticated approach is to use the content of the page to create the meta description.


The following PHP code takes a text field, such as a product description, as input and generates an excerpt that will serve as a good meta description.  Use that excerpt as the ‘content’ attribute value in the meta description tag.

/* This PHP Function generates a meta description string at 
least 80 characters long, ending with a period if possible, and no 
more than 156 characters. The output of this function should probably
be html encoded with a function such as htmlspecialchars() for use
in a web page. */

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


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 about technical SEO, please contact Hochman Consultants.