Skip to main content

How to Exclude a Category From Your WordPress Homepage

This method requires you to add code to your WordPress files. If you haven’t done this before, then see our guide on how to copy and paste code snippets in WordPress.

You will need to add following code to your theme’s functions.php file or a site-specific plugin.


function exclude_category_home( $query ) {

if ( $query->is_home ) {

$query->set( 'cat', '-5, -9, -23' );


return $query;


add_filter( 'pre_get_posts', 'exclude_category_home' );


Hide specific categories from category widget

function exclude_widget_categories($args){
    $exclude = "227,226";
    $args["exclude"] = $exclude;
    return $args;