Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save taricco/19926940d85b1e8ad83901f0e4193bf0 to your computer and use it in GitHub Desktop.

Select an option

Save taricco/19926940d85b1e8ad83901f0e4193bf0 to your computer and use it in GitHub Desktop.
/*** Rewrite the "Category base" and "Tag base"
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_action( 'init', function() {
global $wp_rewrite;
// Set clean category and tag bases
$wp_rewrite->category_base = 'sort-by';
$wp_rewrite->tag_base = 'sort-by/tag';
// Prevent Permalink "Custom Structure" prefix from attaching to taxonomies
$wp_rewrite->use_trailing_slashes = true;
// Register a manual rewrite rule for /sort-by/tag/ URLs
add_rewrite_rule(
'^sort-by/tag/([^/]+)/?$',
'index.php?tag=$matches[1]',
'top'
);
// Flush rewrite rules only if necessary (e.g., after code changes)
if ( get_option( 'wsv_rewrites_flushed' ) !== '1.0' ) {
flush_rewrite_rules( false );
update_option( 'wsv_rewrites_flushed', '1.0' );
}
}, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment