Add Custom Taxonomy Title Tags Support to All-In-One SEO Pack

August 23, 2009

in WordPress

Get control over your custom taxonomy’s Title Tag

With Yoast’s Simple Taxonomies plugin, you can set up a custom categorization system for posts on your site known as a custom taxonomy. When trying to optimize these pages, I realized that the All in One SEO Pack plugin doesn’t have support for custom taxonomies, so it will not format the title properly. I’ve slapped together some code to improve the formatting of the title tag. See this code in action.

1. Modify the aioseop.class.php file in the all-in-one-seo-pack plugin folder.

2. After this code (around line line 398):

else if ($query->is_tag  && $haspost) {
  $tag = get_term_by('slug',get_query_var('tag'),'post_tag');
  if (!empty($tag->term_id)) {
    $link = get_tag_link($tag->term_id);
  }
  $link = $this->yoast_get_paged($link);
}

3. Add the following code:

else if ($query->is_term  && $haspost) {
  $term = get_term_by('slug',get_query_var('term'), get_query_var( 'taxonomy' ));
         if (!empty($term->term_id)) {
                $link = get_tag_link($term->term_id);
         }
     $link = $this->yoast_get_paged($link);
}

4. Find the following code (around line 641):

  $title = trim($title);
  $title = apply_filters('aioseop_title_single',$title);
  $header = $this->replace_title($header, $title);
}

5. And add the following code after it:

else if (function_exists('is_taxonomy') && get_query_var('term')) {
  $term     = get_query_var('term');
  $taxonomy   = get_query_var('taxonomy');
    if ($term) {
      $term = str_replace('-', ' ', $term);
      $term = $this->capitalize($term);

      $taxonomy = $this->capitalize($taxonomy);
      $taxonomy = ' - '.$taxonomy;
      $title_format = $aioseop_options['aiosp_tag_title_format'];

      $title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
      $title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
      if($taxonomy) {
        $title = str_replace('%taxonomy%', $taxonomy, $title);
      }
      else {
        $title = str_replace('%taxonomy%', '', $title);
      }
      $title = str_replace('%tag%', $term, $title);
      $title = $this->paged_title($title);
      $title = apply_filters('aioseop_title_single',$title);
      $header = $this->replace_title($header, $title);
    }
}

6. Find the following code (near line 736):

$title = str_replace('%tag%', $tag, $title);

7. And add the following code after:

$title = str_replace('%taxonomy%', '', $title);

8. Now your site is set up to allow for your custom taxonomy title tags. You can now configure the way that the order in which the taxonomies are displayed by editing the “Tag Title Format” setting in the All in One SEO Pack settings page.

I have it configured on the Egret Windows website as: %tag% %taxonomy% | %blog_title%

Leave comments below with any questions.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Twitter

Related posts:

  1. Add Custom Titles for Tags and Categories in WordPress
  2. Rich Text Tag, Category, and Taxonomy Descriptions for WordPress
  3. Remove shortcode from All in One SEO Pack in WordPress 2.6
  4. Add Canonical Tags to Shopp Plugin for SEO
  5. Simple Taxonomies Formatting — Improve the Plugin’s Code Output

1 comment… read it below or add one

anekdot June 24, 2010 at 2:01 pm

Thanks for post! I`ll try the taxonomy on my new site.

Reply

Leave a Comment

Previous post:

Next post: