in functions.php, I wrote this code:
function remove_category($query) {
if (!is_admin() && ($query->is_category() || $query->is_tag())) {
$category = get_queried_object();
$query->set('post_type', 'post');
$query->set('category_name', $category->slug);
$category_id = $category->term_id;
$category_link = get_category_link($category_id);
$url = $category_link;
$arr = parse_url($url);
$path = $arr['path'];
$str_to_arr = explode('/', $path);
$archive = $str_to_arr[2];
$new_url = str_replace('/' . $archive, '', $url);
echo "New URL: {$new_url}";
}
return $new_url;
}
The code actually filters out category or tags based on the custom theme I am working on.
Now I have tried applying ‘site-url’ filter hook, but the site breaks. How can I able to achieve this?
New contributor
Suborno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.