Last active
August 29, 2015 14:01
-
-
Save tlovett1/d1fe551e7ee7091d898e to your computer and use it in GitHub Desktop.
Strip taxonomy base from URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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