Categories
WordPress

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

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.

By Zack Katz

Zack Katz is the founder of GravityKit and TrustedLogin. He lives in Leverett, Massachusetts with his wife Juniper.

5 replies on “Add Custom Taxonomy Title Tags Support to All-In-One SEO Pack”

I found one issue with this code:

It doesn’t render letters like å,ä, ö correctly in the TITLE (instead we got letters as a,a,o). I also don’t want it to strip away carachters like “&”. Do you know how to fix this?

If you have a solution I would be more than happy if you could send me an email.

Thanks in advance!

And if you want to add the description just find this line : 

$keywords = apply_filters(‘aioseop_keywords’,$keywords);

and add just before :if (function_exists(‘is_taxonomy’) && get_query_var(‘term’)) {  $taxonomy   = get_query_var(‘taxonomy’);  $termedesc = term_description( ”, $taxonomy ); if ($termedesc) {  $term = str_replace(”, ”, $termedesc);  $term = str_replace(”, ”, $term);  //$term = $this->capitalize($term); $description = $term; } $meta_string .= sprintf(“”, $description); }

Comments are closed.