2

I have a situation where i have a lot of tags and i want to add custom taxonomies to sort them. But the thing is when i register new taxonomy i cannot use tag slug.

Example (Tag Taxonomy)

example.com/tag/artist-name

Changed to (Artist Taxonomy)

example.com/tag/artist-name

As you can see, i want to change taxonomy while preserving permalinks. I want to list tags based on couple things. But tags are just tags there is no sorting by type with them. I should have used custom taxonomies from the beginning but its too late now.

If i change tags to new taxonomy it will look like this

example.com/artist/artist-name

And i will have a lot of 404 pages. How do i even redirect 1k pages? Especially since they are just part of the tags. I would really have to add redirects one by one.

  • 1
    Add this to your .htaccess file RewriteEngine On RewriteRule ^tag$ /artist [R=301,L] – Sam May 19 '17 at 20:03
3

You shouldn't and most likely can't achieve what you are looking for. The tag taxonomy term is reserved by WordPress itself, as well as a couple of other terms. Take a look into this page from the codex.

If you use the same slug for different taxonomies, that would defeat the purpose. For example, categories and tags are taxonomies themselves.

Imagine having two categories, /cat/ and /dog/, both pointing to /animals/. The WordPress itself won't allow you to do that, but let's say you do this by hacking the database. What should be shown when you visit /animals/ slug? cats or dogs?

The worse scenario is to even mix different taxonomy types. Then the WordPress can't even decide what template file to use!

Unfortunately WordPress is not optimized to make this happen for you just by writing a simple rule. I myself had to redo a lot of works sometimes, just because i didn't to it the proper way at the beginning. Your other option would be to write an SQL query or a plugin to alter the data for you and save it in a new format.

Even if you write some rewrite rules to achieve this, you will end up with a messed up website, random 404 pages and incorrect content output.

  • I see. Unfortunately it is how it is. I was aware about potential problems with the same names in multiple taxonomies. I hoped there would be a workaround it. Especially since tags work a bit different than categories. If i used categories instead of tags i could still somehow make it work without much work. By using sub categories. It is possible to delete parent category slug from sub category link right? – Recofa May 19 '17 at 21:16
  • It is still good that you didn't go with this, to end up with 2 problems. Do you mean in permalink? If so then yes, you can visit here to find the proper tag to use. – Jack Johansson May 20 '17 at 0:43
1

There are plugins available that will convert taxonomies - search for something like "taxonomy converter" and you will find some.

After you've converted them, a simple .htaccess redirect will take care of the URLs:

RewriteEngine On
RewriteRule ^tag/(.*)$ http://example.com/artist/$1 [R=301,L]

This will redirect anything under a /tag/ folder, save the subfolder (i.e. artist-name) and redirect it to example.com/artist/artist-name - for all artist-names.

Just change example.com and place these lines above the default WP .htaccess contents.

  • This redirect is not good for me. As i mentioned tags to be changed are only part of all of the tags. Not to mention i want multiple custom taxonomies. It will break all the links. What i want to know is it possible to use one slug for multiple taxonomies? Or any other way to somehow sort tags, so when i call for artists i get artists. – Recofa May 19 '17 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.