admin管理员组

文章数量:1122846

in functions.php, I wrote this code:

function remove_category($link) {
    if (!is_admin() && (is_category() || is_tag())) {

        
        $category = get_queried_object();
        $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);
        
        return $new_url;
    }
    return $link;
}
add_filter('term_link', 'remove_category',10,1);

The code actually filters out category or tags based on the custom theme I am working on.

Now I have tried applying 'term_link' filter hook, but the site breaks. How can I able to achieve this?

本文标签: