How to remove store base from permalink in PremiumPress coupon theme

Sometimes we want to remove /store/ from the store url. We only want store name, like http://yoursite.com/amazon/ instead of http://yoursite.com/store/amazon/

This code can remove store base permalink in premiumpress coupon theme. Add this code to your current theme’s functions.php file:

[php]
add_filter(‘request’, ‘obs_change_term_request’, 1, 1 );

function obs_change_term_request($query){

$tax_name = ‘store’;

if( $query[‘attachment’] ) :
$include_children = true;
$name = $query[‘attachment’];
else:
$include_children = false;
$name = $query[‘name’];
endif;

$term = get_term_by(‘slug’, $name, $tax_name);

if (isset($name) && $term && !is_wp_error($term)):

if( $include_children ) {
unset($query[‘attachment’]);
$parent = $term->parent;
while( $parent ) {
$parent_term = get_term( $parent, $tax_name);
$name = $parent_term->slug . ‘/’ . $name;
$parent = $parent_term->parent;
}
} else {
unset($query[‘name’]);
}

$query[$tax_name] = $name;

endif;

return $query;

}

add_filter( ‘term_link’, ‘obs_term_permalink’, 10, 3 );

function obs_term_permalink( $url, $term, $taxonomy ){

$taxonomy_name = ‘store’;
$taxonomy_slug = ‘store’;

if ( strpos($url, $taxonomy_slug) === FALSE || $taxonomy != $taxonomy_name ) return $url;

$url = str_replace(‘/’ . $taxonomy_slug, ”, $url);

return $url;
}

add_action(‘template_redirect’, ‘obs_old_term_redirect’);

function obs_old_term_redirect() {

$taxonomy_name = ‘store’;
$taxonomy_slug = ‘store’;

if( strpos( $_SERVER[‘REQUEST_URI’], $taxonomy_slug ) === FALSE)
return;

if( ( is_category() && $taxonomy_name==’category’ ) || ( is_tag() && $taxonomy_name==’post_tag’ ) || is_tax( $taxonomy_name ) ) :

wp_redirect( site_url( str_replace($taxonomy_slug, ”, $_SERVER[‘REQUEST_URI’]) ), 301 );
exit();

endif;

}
[/php]

Spread the love