Adding Meta Descriptions to Taxonomy Pages

In the previous meta description entries  I created a meta description field for my content type, altered my page.tpl to show the meta description if it was available and used the site $mission field to use as the front page meta description.

Now I need to alter it again to use a taxonomies term description as the meta description for those pages. I also added a title alteration for paginated pages.

The top portion of my page.tpl now (currently using zen theme)
<?php
$title_addon = '';
if ($_GET['page']>0){
  $title_addon = $_GET['page'] +1;
  $title_addon = ' - Page ' . $title_addon;
}
$meta = '';
if ($is_front) {
    $meta = '<meta name="description" content="' . strip_tags($mission) . ' ' . $title_addon  .'" />';
    //using strip_tags instead of check_plain() as check_plain will convert markup into entities we just want stripped out
}elseif(isset($node->field_meta_description[0]['value']) && strlen($node->field_meta_description[0]['value'])>0) {
    $meta = '<meta name="description" content="' . strip_tags($node->field_meta_description[0]['value']) . '" />';

}elseif(arg(0) == 'taxonomy' && arg(1) == 'term' && arg(2)>0){
  $term_ob = taxonomy_get_term(arg(2));
 
  $description = $term_ob->description;
  if (strlen($description)>0){
     
      $meta = '<meta name="description" content="' . strip_tags($description) . ' ' . $title_addon . '" />';
  }else{
      //Tags are created on the fly by authors and may not have a description use the term name to have something in
      $meta = '<meta name="description" content="' . strip_tags($term_ob->name) . ' entries ' . $title_addon . '" />';
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" lang="<?php print $language->language; ?>" dir="<?php print $language->dir; ?>">
<head>
  <title><?php print $head_title . ' ' . $title_addon; ?></title>
  <?php print $meta;?>

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.