Title: Adding exclude category function breaks the Theme
Last modified: November 17, 2019

---

# Adding exclude category function breaks the Theme

 *  [derlynad](https://wordpress.org/support/users/derlynad/)
 * (@derlynad)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/adding-exclude-category-function-breaks-the-theme/)
 * Hello!
 * I’m making preparations to migrate from the old theme to Twenty Twenty and found
   another issue.
 * I created a new child theme, and tried to put a typical function to functions.
   php file in order to exclude some categories from the loop.
 *     ```
       /*Delete category from the loop*/
   
       function exclude_category($query) {
        if ($query->is_home){
        $query->set('cat','-37');} 
        return $query; }
       add_filter('pre_get_posts','exclude_category');
       ```
   
 * This function worked just fine on my previous themes, but in the case of Twenty
   Twenty it returns a blank white screen and nothing more (in the front and admin
   panel).
 * Maybe there is an alternative way to exclude categories from the loop, especially
   if I try to use a static home page, and the main loop with posts on the subpage(
   ex. example.com/blog)?
 * Any ideas appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [derlynad](https://wordpress.org/support/users/derlynad/)
 * (@derlynad)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/adding-exclude-category-function-breaks-the-theme/#post-12143272)
 * Any other similar functions like this:
 *     ```
       function filter_pre_get_posts( $query ) {
           if ( is_home() && $query->is_main_query() ) {
               $query->set( 'category__not_in', array( '37' ) );
           }
       }
       add_action( 'pre_get_post', 'filter_pre_get_posts' );
       ```
   
 * result in the same blank screen 🙁
 *  [Jarret](https://wordpress.org/support/users/jarretc/)
 * (@jarretc)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/adding-exclude-category-function-breaks-the-theme/#post-12144579)
 * I tried the first block of code that you supplied adjusting for the category 
   ID in my TwentyTwenty child theme and it removed the posts from the homepage 
   loop.
 * Maybe you have a typo somewhere in there causing the white screen? I’m not sure
   if you’re developing this on a live site or something like localhost but you 
   should be able to check the error log somewhere or try setting WP_DEBUG in your
   wp-config.php to true to get the actual error message to display.
 *  Thread Starter [derlynad](https://wordpress.org/support/users/derlynad/)
 * (@derlynad)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/adding-exclude-category-function-breaks-the-theme/#post-12144682)
 * Thanks a lot, [@jarretc](https://wordpress.org/support/users/jarretc/)! There
   was a typo indeed in another function above.
 * Will this filter solution work for the subpage, as [https://example.com/blog](https://example.com/blog)?
 *  [Jarret](https://wordpress.org/support/users/jarretc/)
 * (@jarretc)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/adding-exclude-category-function-breaks-the-theme/#post-12145210)
 * If /blog is the page you have set under Settings->Reading as the Posts Page then
   yes.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Adding exclude category function breaks the Theme’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/twentytwenty/3.1/screenshot.png)
 * Twenty Twenty
 * [Support Threads](https://wordpress.org/support/theme/twentytwenty/)
 * [Active Topics](https://wordpress.org/support/theme/twentytwenty/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/twentytwenty/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/twentytwenty/reviews/)

## Tags

 * [blank-screen](https://wordpress.org/support/topic-tag/blank-screen/)
 * [exclude categories](https://wordpress.org/support/topic-tag/exclude-categories/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 4 replies
 * 2 participants
 * Last reply from: [Jarret](https://wordpress.org/support/users/jarretc/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/adding-exclude-category-function-breaks-the-theme/#post-12145210)
 * Status: not resolved