Skip to content

Instantly share code, notes, and snippets.

@omniacode
Last active August 17, 2018 04:20
Show Gist options
  • Save omniacode/1ae5bbde9c516688e19dfd8b1a8de99d to your computer and use it in GitHub Desktop.
Save omniacode/1ae5bbde9c516688e19dfd8b1a8de99d to your computer and use it in GitHub Desktop.
// Remove Taxonomy Slug
add_filter( 'term_link', 'remove_tax_slug_link', 10, 3 );
function remove_tax_slug_link( $link, $term, $taxonomy ) {
if ( $taxonomy !== 'your-taxonomy-name' )
return $link;
return str_replace( 'your-taxonomy-name/', '', $link );
}
add_action('init', 'custom_tax_rewrite_rule', 10, 0);
function custom_tax_rewrite_rule() {
$cats = get_terms(
'your-taxonomy-name', array(
'hide_empty' => false,
)
);
if( sizeof($cats) )
foreach( $cats as $cat )
add_rewrite_rule( $cat->slug.'/?$', 'index.php?your-taxonomy-name='.$cat->slug, 'top' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment