Removing the tag prefix could possibly pose a conflict with a post/page but if you must, give the following code a try, insert into your functions.php file:
function remove_tag_prefix( $rules ) {
foreach ( $rules as $rule => $rewrite ) {
if ( preg_match( '/tag\/(.+)/', $rule, $matches ) ) {
$new_rule = str_replace( 'tag/', '', $rule );
unset( $rules[ $rule ] );
$rules[ $new_rule ] = $rewrite;
}
}
return $rules;
}
add_filter( 'rewrite_rules_array', 'remove_tag_prefix' );
This code uses the preg_match
function to match the “tag/” portion of the rule, and then removes it from the rule using str_replace
. The modified rules are returned, effectively removing the tag prefix from the URLs.
After adding this code, you should flush the rewrite rules for the changes to take effect. You can do this by going to “Settings” -> “Permalinks” in your WordPress dashboard and simply clicking the “Save Changes” button.