admin管理员组

文章数量:1134249

I need to hide the Uncategorized category from the default sidebar.

I edited the file wp-includes/widgets/class-wp-widget-categories.php, but I did not see any changes. Here is an image of my sidebar, where the blog is listed under the "Uncategorized" category, which I want to hide.

how can i achieve this?

I need to hide the Uncategorized category from the default sidebar.

I edited the file wp-includes/widgets/class-wp-widget-categories.php, but I did not see any changes. Here is an image of my sidebar, where the blog is listed under the "Uncategorized" category, which I want to hide.

how can i achieve this?

Share Improve this question edited Jul 27, 2023 at 6:55 Arsalan Mithani 5534 silver badges15 bronze badges asked Jul 24, 2023 at 18:58 waqas023waqas023 52 bronze badges 2
  • That's not the default WordPress sidebar. It's a widget or block added by a theme or plugin. – Jacob Peattie Commented Jul 25, 2023 at 11:41
  • How I can found this code – waqas023 Commented Jul 25, 2023 at 14:14
Add a comment  | 

1 Answer 1

Reset to default 0

Editing the core WordPress files (like class-wp-widget-categories.php) directly is a no-go. When WordPress updates, it'll overwrite any changes you made to the core files. Plus, it's generally frowned upon in the developer community—it's just not a good habit to get into.

If the widget you're using is the core's default category widget, try adding the following code to your theme's functions.php file:

function exclude_categories($args){
    $exclude = get_cat_ID('Blog'); // Get the ID of the category you want to exclude
    $args["exclude"] = $exclude; // Exclude the category
    return $args;
}
add_filter("widget_categories_args","exclude_categories");

After adding this, the "Blog" category should disappear from the sidebar. If it's still playing coy, clear your cache, then take another look.

本文标签: theme developmenthow can i modify the default wordpress sidebar