Prefixing a Custom Taxonomy in WordPress

I’m currently working on a website with a custom portfolio section. It’s making use of a custom post type called project and two attached custom taxonomies called market, and service. The portfolio page exists here:

displaying all the projects. Each project live here:<project-slug>

Everything was going fine until I realized that my custom taxonomies were not as separated from the main blog as I would like them to be. Consider the following taxonomy archive URLs:<market-slug><service-slug>

and the very similar pages already on the site:

etc. What I needed to do was to group the taxonomy archives under the portfolio page in the URL structure, turning<market-slug>


But how does one prefix a custom taxonomy URL in WordPress with a static value such as ‘/portfolio/‘ ? The answer is pretty easy, it turns out.

Put That Slash in the Slug

All you need to do is add the static prefix value to the slug portion of the rewrite argument when registering the taxonomy. For example:

$serviceArgs = array(
		'labels'     => $serviceLabels,
		'query_var'  => 'service',
		'rewrite'    => array( 'slug' => 'portfolio/service' ) //was 'service'
	register_taxonomy( 'project_service', null, $serviceArgs );

After you make the update, flush your rewrite rules and you are good to go!

More info on register_taxonomy().

Leave a Reply

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