theme development – Getting white screen of death on category pages because of body_class() function


Category pages “” were working fine and then suddenly started showing white screens.

Debug showed no output. No errors in apache logs either. So I started debugging with print statement and found the issue in header.php file: Commenting out body_class fixes the issue and the category pages load:

<body <?php //body_class(); ?>>

How might I find the root cause of this problem?

UPDATE: Commenting out this code in get_body_class() function fixes the problem, too:

            } elseif ( is_category() ) {
                        $cat       = $wp_query->get_queried_object();
                        $classes[] = 'category';
                        if ( isset( $cat->term_id ) ) {
                                $cat_class = sanitize_html_class( $cat->slug, $cat->term_id );
                                if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) {
                                        $cat_class = $cat->term_id;

                                $classes[] = 'category-' . $cat_class;
                                $classes[] = 'category-' . $cat->term_id;

UPDATE 2: This is really weird. If I drop a echo '.' statement right after the $cat = $wp_query->get_queried_object(); line in the function above, everything works! If I do echo ' ' instead, it breaks again! WTF???

in progress 0
StevieD 2 years 2022-03-03T07:40:43-05:00 0 Answer 0 views 0

Answer ( 1 )


    OK, figured out this bizarreness. My big mistake: assuming a white screen of death was some kind of code error with PHP. It was actually some badly coded css on my part that hid the entire body from view! All I had to do is look at the source code to see all the code was there.

    So that explains why there were no errors and why throwing an echo statement that output to the screen magically “fixed” things; because it broke the css rendering.

    One of those days.

    And pro tip: don’t work on 3 hours of sleep.

Leave an answer