Skip to content

Instantly share code, notes, and snippets.

@tlovett1
Last active August 29, 2015 14:01
Show Gist options
  • Save tlovett1/d1fe551e7ee7091d898e to your computer and use it in GitHub Desktop.
Save tlovett1/d1fe551e7ee7091d898e to your computer and use it in GitHub Desktop.
Strip taxonomy base from URL
<?php
function tl_filter_term_link( $termlink, $term, $taxonomy ) {
if ( 'taxonomy' != $taxonomy )
return $termlink;
$termlink = str_ireplace( 'taxonomy/', '', $termlink );
return $termlink;
}
add_filter( 'term_link', 'tl_filter_term_link', 10, 3 );
function tl_tax_check( $query_vars ) {
if ( isset( $query_vars['pagename'] ) ) {
// Todo: hardcode category ID's
$tax_name = $query_vars['pagename'];
if ( strpos( $tax_name, '/' ) !== false )
$tax_name = preg_replace( '#[^/]*/(.*)#is', '$1', $query_vars['pagename'] );
if ( $tax = wpcom_vip_get_term_by( 'slug', $tax_name, 'taxonomy' ) ) {
$query_vars['taxonomy'] = $tax_name;
unset( $query_vars['pagename'] );
}
}
return $query_vars;
}
add_filter( 'request', 'tl_tax_check' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment