Taxonomic SEO Permalinks

Custom WordPress Taxonomy feature was introduced hoping that it will help users create some kind of groups just like regular WordPress category or tags. Custom taxonomies gives control over personalizing the blog to great extend. Now users can create meaningful taxonomies that suits the subject.

When I tried to create projects by using the taxonomies, I just had a problem, and that was with using taxonomies in URLs. I found that WordPress does support the feature that helps in custom taxonomies in queries, but as I tried and tested, I couldn’t use them in Permalink settings just like we use /%category%/%postname%/. So I created this plugin.

You can download Taxonomic SEO Permalinks plugin from website.

TSP Version 0.3.1

Now supports sub-taxonomy in URLs. People requested me to support sub-taxonomy just like WordPress supports sub-category in URLs. For example if you use %category% in permalink structure and a post has sub-category, %category% will be replaced with ‘parent-category-slug/child-category-slug’.

In order to do similar things with custom taxonomies I tried many things but the solutions was getting complicated just because of forward slash (/) character as separator. So in order to keep things as simple as possible I used plus (+) character to separate child and parent custom taxonomies. I know this is not what most of us want but still it solves sub-taxonomy problem. I will fix this as soon as possible.

Also I used a limit of three parts per replacement. So a custom taxonomy structure tag can be replaced with ‘grandparent-slug+parent-slug+child-slug’ at the max and won’t show ‘great-grandparent-slug’ even if present.

TSP Version 0.2.0

Few major changes done on programming side. The plugin is made more general and should be working without any manual changes. No need to edit plugin file, almost everything is done automatically.

TSP Version 0.1.3 and Earlier

This version was written to work on both standalone blog as well as network blog. Also taxonomies needed to be edited manually inside plugin.

Published by

Rakesh Tembhurne

I am a developer from India. Visit my Google+ profile for more information:

23 thoughts on “Taxonomic SEO Permalinks”

  1. Och man, you saved my life! I was really upset of this issue… after hours research i found this! Really and deeply thank you…

  2. Hi, nice plugin — I edited it so if a taxonomy value doesn’t exist, it doesn’t return anything and configured the following:

    My permalink setup: /%category%/%postname%%taxonomyname%/
    In plugin code (line 99): $permalink = str_replace($tax_token, ‘-‘.$long_slug, $permalink);
    (I added a leading “-“)

    Desired URLs:
    IF taxonomy exists:
    IF taxonomy doesn’t exist:

    Here are the resulting post URLs:
    IF taxonomy exists: (as intended, but leads to a 404 page)
    IF taxonomy doesn’t exist: (don’t want the trailing “-“)

    Is there a way I can get the desired URLs and not resolve a 404?

    Thanks for your help.

    1. Patrick, WordPress reads the URL entered and it divides it into pieces according to rules (WP Rewrite) defined with the help of regular expressions. It treats ‘/’ (forward slash) as a separator and it’s difficult to understand for WordPress when we use ‘-‘ (dash / hyphen) as separator, which is also used as a replacement for space. So when URL contains something like “…/my-real-post-name/” which is actually replacement for %postname%, it is divided (sliced) into a piece and compared with post name slugs in database. Problem with URLs like is that regular expressions will compare /postname-taxonomy/ part with post name slugs in the database, causing 404 page.

      I think, we cannot skip one of the pieces like category or custom taxonomy if you have mentioned it in permalink structure. That’s why when we don’t specify a category to a post, ‘uncategorized’ appears in the post URL. This plugin replaces ‘no-taxonomy’ if taxonomy is not specified for the post. However, there might be a fix around. If you find it, let me know.

  3. Hi Rakesh, thanks for the reply. What’s odd is–taxonomy/ (with 2 hyphens) does resolve properly. Still working on hiding the trailing “-” however.

    Related, if I went with the following URL:

    …if both taxonomy fields are null (blank), how could I prevent the following URL?: (note the extra slashes)

    Thanks again.

    1. You will need to tweak functions for doing these. You can either give taxonomy a default value inside functions just like ‘uncategorized’ or you can tweak the part of functions where %taxonomy1% is being replaced. Remember to add WP Rewrite rules to accept your ‘’ URL.

  4. Starting the permalink structure with a custom taxonomy works for posts, however it breaks WP page URLs.

    If I move the custom taxonomy in the permalink structure to not start at the begining of the URL, it works for WP pages. Example:

    Is there a work around?

    1. Hello,
      If you read the code, it is just a two step hack. First, looping through custom taxonomies, add rewrite tags

      add_rewrite_tag($tax_token, ‘(.+)’, $tax_name.’=’);

      Second, it reads the permalink structure set by user, and for each post it replaces %my_taxonomy_token% with value set in the post for that taxonomy.

      For each of these step there is a separate function. If you can use the same logic to iterate through custom post types, you might get desired output. I will look into this as soon as possible, and if you solve the problem before I do, let me know.

  5. Hey Rakesh,

    thanks for this great plugin. I’ve been using it for a coulpe of days now, but i’m runnng into _one_ single problem.

    my permalinks look like this:

    if a post is /themovie/category-one/postname/ it works. but it doesn’t with sub-categories, for example: /themovie/category-one/sub-category-one/postname/

    this gives me an 404 error page.
    do you have a trick that might work? :)

  6. Little correction:
    /themovie/category-one/ works
    /themovie/category-one/sub_category/ doesn’t
    /themovie/category-one/sub_category/postname/ works

    any ideas? :)

  7. Hey rakesh,

    is there a way to make your plugin work with sub-categries?
    my current structure is this:

    what’s weird:
    /%thetag%/category/ works!
    /%thetag%/category/subcategory/ doesn’t work
    /%thetag%/category/subcategory/post works!

    do you have any idea, what might cause it? or might fix it?


    1. It does not work on any other term. It simply just replaces %thetag% with the text for that taxonomy… When url entered, it just ignores taxonomy, and take other parts of url for getting post / category information.

      1. hey rakesh,
        thx for your quick reply.

        that’s my problem, it’s doesn’t get all other information. my permalink-settings look like this:

        if subcategories are entered, it should contain them in the url, right?
        currently it gives me a 404.

  8. This works fine… But im getting 404 errors while i try to view the pages. Any changes that we can make to correct this issue?

    Please let me know


  9. Hi Rakesh, Thanks for this plugin. It’s quiet old and now we have custom post types and custom taxonomies. I’m trying to fit in but just couldn’t. If I change anything I will help you update the code.


Leave a Reply