How to Fix the “ob_end_flush() zlib” Notice in WordPress

In WordPress, some errors come as a surprise and don’t seem related to anything you have previously done. Sometimes, it can be caused by a plugin, other times it is just about your server setup.

Nevertheless, even it is just a notice and not an error that prevents your site from loading, you should always fix it.

If you see the notice “Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in” appear, it is quite easy to fix.

The Solutions

There are several solutions that take different paths to solve this issue.

wp-config.php solution

Go to edit your wp-config.php file and add the following line.

ini_set('zlib.output_compression', '0');

functions.php solution

For this solution, go in your WordPress theme and open the functions.php file to edit it. Add the following line.

remove_action('shutdown', 'wp_ob_end_flush_all', 1);

Removing the general display of notices

Once you are done and checked that these notices stopped appearing, you should, however, ensure that notices will not appear if your website is live.

For that purpose, add or edit the following lines of code in your wp-config.php file at the root of your WordPress installation.

// Disable WP_DEBUG mode
define( 'WP_DEBUG', false );

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

This way, even if there is a PHP warning, it will not be displayed on the site, which could be a security issue. For debugging purpose, I suggest that you use a staging site.