I updated handle_buffer to check the wp_query object so the header is not inserted inappropriately.