This topic has 2 replies, 2 voices, and was last updated 3 months ago ago by Andrew Mitchell
Hello.
We have a small problem with the Brands link, it is like this:
https://localhost/brand/flores-cbd/ and we need it to be https://localhost/flores-cbd/ without brand.
How could we do this?
Thank you very much
Hello, OnlyCBD,
Thank you for reaching out to us. To remove the brand from the URL, you need to add the following code to the functions.php file of your child theme:
// Remove /brand/ prefix from brand taxonomy URLs
function custom_brand_rewrite_rules($flash = false) {
$taxonomy = 'brand';
$terms = get_terms($taxonomy, array('hide_empty' => false));
foreach ($terms as $term) {
add_rewrite_rule(
$term->slug . '/?$',
'index.php?' . $taxonomy . '=' . $term->slug,
'top'
);
}
if ($flash) {
flush_rewrite_rules(false);
}
}
add_action('init', 'custom_brand_rewrite_rules', 10, 0);
function custom_brand_term_link($termlink, $term, $taxonomy) {
if ($taxonomy === 'brand') {
return home_url('/' . $term->slug . '/');
}
return $termlink;
}
add_filter('term_link', 'custom_brand_term_link', 10, 3);
After that, go to Settings > Permalinks.
Click the “Save Changes” button to flush the rewrite rules and apply the changes.
If you need further assistance or have any questions, please feel free to contact us.
Best Regards,
8Theme’s Team
You must be logged in to reply to this topic.Log in/Sign up