WordPress rewrite rule for custom taxonomies

This makes it possible to have the taxonomy below some post type slug, e.g. the post type is at /cars/ and taxonomies are at /cars/manufacturer/, /cars/year-of-construction/ etc.

You want to register the taxonomy with the same $slug.


add_action( 'generate_rewrite_rules', 'taxonomy_rewrite' );

function taxonomy_rewrite( $wp_rewrite ) {
  $slug = 'yeah/this/is/what/i/want';
  if ( preg_match( '/\//', $slug ) ) {
    $new_rules = array(
      "$slug/(.+)" => 'index.php?paste_tag=' .
       $wp_rewrite->preg_index( 1 )
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;


Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityFontGnuPGThunderbirdJenkins