Custom Taxonomy URL in WordPress

When you create a custom post type and a new taxonomy for that post type, you will notice that the URLs for the taxonomy values do not follow the same format as the blog category taxonomy value URLs.

For example, if one of the category values for your blog post is “mobile”, the URL would be:

Now, if you have a custom post type called “portfolio” and a category taxonomy where one of the taxonomy values is “mobile,” then the URL would be:

Instead of

And sometimes, the custom post itself will be under “-category” URL like following:
Now, this wasn’t that big of a deal until I realized that this would kinda mess up the analytics.  For example, what if you wanted to see which post type had the most traffic in Google Analytics and you were looking at Page path level 1, i.e., the first subdirectory in the request URI?  It would exclude all the data that went to /portfolio-category/* when looking at the traffic for the portfolio post type.

If you Google this, you may find a few articles presenting potential solutions.  But if all you really need is for the analytics purpose, then there is a quick way to resolve this in Google Analytics.

You can add a “Search and Replace” filter to your view.

Filter Name: any name
Filter Type: Custom -> Search and Reaplce
Filter Field: Request URI
Search String: /portfolio-category/mobile/
Replace String: /portfolio/category/mobile/

Here is a screenshot:

Using Filter to fix WordPress custom taxonomy URL

This will fix any data issues created by the weird URLs.