Remove taxonomy base or term from url

When I do this, I get the desired
result from this page, but all of my
other page links break (using
permalinks.)

Because, quite simply, WordPress hasn’t got a clue you’re asking for a page. It’s doing what you told it to do;

For all URLs that look like http://example.com/X, look for posts with messagetype’s of X.

That’s why you need the ‘identifier’ in there; so that it can distinguish the difference between requests for pages, archives, categories…

If you really want this functionality, adding verbose rewrite rules at the top of the rewrite map would be the way to go;

add_rewrite_rule( 'media/?$', 'index.php?messagetypes=media', 'top' );

If you’ve got a lot of messagetypes, you might want to hook into the creation and deletion of terms and dynamically update & flush the rewrite rules.

Otherwise, repeat the example for each term in your functions.php, then flush your permalinks (just visit the permalink options page in admin).

One last thing, revert your register_taxonomy call ‘back to normal’ i.e. leave out the rewrite argument, and use the term_link filter to swap in the custom permalink ourselves;

function __custom_messagetypes_link( $link, $term, $taxonomy )
{
    if ( $taxonomy !== 'messagetypes' )
        return $link;

    return str_replace( 'messagetypes/', '', $link );
}
add_filter( 'term_link', '__custom_messagetypes_link', 10, 3 );

Leave a Comment

tech