PHP Warning: Cannot modify header information – headers already sent

Usually, getting such errors on your WordPress site or in the error_log file means that you have extra spaces or lines before or after the opening and closing PHP tags, <?php and respectively ?> . This happens mostly to files from the current theme.

In the error_log file you will see entries like:

[30-Jan-2020 10:55:08 UTC] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/site1/public_html/wp-content/themes/BlogTheme/functions.php:1) in /home/site1/public_html/wp-content/themes/BlogTheme/functions.php on line 873
[30-Jan-2020 10:55:31 UTC] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/site1/public_html/wp-content/themes/BlogTheme/functions.php:1) in /home/site1/public_html/wp-content/themes/BlogTheme/functions.php on line 873

So, to fix these PHP warnings, you must edit the file (e.g functions.php) and double-check for extra lines/spaces. In our case, the warnings were caused by a space before the opening PHP tag:

Extra Space in functions.php

You can edit the file directly from your File Manager in cPanel/Plesk/DirectAdmin etc or you can download the file, edit it and upload it.

Open the WordPress site again and check for any new PHP messages.