Skip to content

WordPress Issue: Cannot modify header information - headers already sent by

This error message appears when a PHP script is trying to modify the headers of an HTTP response after the headers have already been sent. This can happen if there is whitespace, a Byte Order Mark (BOM), or other output before the call to the header() function, or if a PHP error or warning message is being output to the browser. To fix this issue, you'll need to find the source of the output and remove it. This could be an echo statement, a print statement, a debugging message, or a plugin or theme that is not properly configured. You can also check for any blank spaces or unnecessary characters before the opening <?php tag in your files.

Locate the exact file: Enable WP_DEBUG and WP_DEBUG_LOG in your wp-config.php file. WordPress will record the exact file and line number where the premature output begins in wp-content/debug.log.

Practical workaround: If you cannot immediately locate the source, enable output buffering at the very top of your wp-config.php or theme's functions.php:

php
<?php
ob_start();
?>

Correct header() placement: Always call header() before any HTML, whitespace, or PHP output:

php
<?php
header('Location: https://example.com');
exit;
?>

Dual-run preview — compare with live Symfony routes.