Hacking Platinum SEO Pack to include parent category names

Platinum SEO Pack is one of our favorite WordPress plugins, we install it on almost all of our sites. While working on improving RMD Motor’s title tags, we wanted to include parent category names in page titles, Platinum SEO Pack does not support this out of the box. I wrote a quick hack to include them.

To include parent category names in your page titles, open up platinum_seo_pack.php and scroll down to line 843 and look for this:

$category_name = ucwords($this->internationalize(single_cat_title('', false))); $title_format = get_option('aiosp_category_title_format'); $title = str_replace('%category_title%', $category_name, $title_format);

Replace that with the following:

$category_name_single = ucwords($this->internationalize(single_cat_title('', false)));
$cat = get_term_by('name', $category_name_single, 'category');
$parentCats = explode('^', get_category_parents($cat->term_id, FALSE, '^', FALSE));
for ($c=0;$c<count($parentCats);$c++) {
$category_name .= $parentCats[$c] . ' ';
}
$title_format = get_option('aiosp_category_title_format');
$title = str_replace('%category_title%', trim($category_name), $title_format);

Now, rather than “RS250” we have “Honda RS250T“, much better!

3 Responses to Hacking Platinum SEO Pack to include parent category names

  1. June 15, 2011 Turisticka agencija Nis

    Thanks, i was looking for this solution.
    Strange thing that Platinum seo programmers didn’t programmed this as a feature…

  2. September 23, 2012 Kerstin

    Thanks for the code.
    Which version of Platinum SEO Pack do you use?

    I try your hack with the Version: 1.3.7 and get an blank white screen when i choose the subcategory.

    • September 24, 2012 Matt McInvale

      I don’t recall what version this was for, sorry.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.