Home / Blog / WordPress
,

Exclude categories from the WordPress category widget

First published 21 Jun 2020. Tested again in November 2026 on WordPress 7.1.4 and PHP 8.4.

Below is the code that you can add to the functions.php file of your active theme to exclude one or more categories from the default WordPress category widget.

function exclude_widget_categories($args){

    $exclude = "1,4,8,57,80"; //Add your category ids here
    $args["exclude"] = $exclude;
    return $args;
    
}
add_filter("widget_categories_args","exclude_widget_categories");

View or fork this snippet on GitHub Gist.

Need this done on a live site? Exivon Tech takes on projects and audits, led by me.

Dhiren Patel

Principal Full-Stack Engineer · Founder, Exivon Tech

I’ve built and run enterprise web platforms and e-commerce for 13 years, and I built ShieldScope, a free WordPress security scanner, and Lede, a free block theme.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.