Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fix Cannot Modify Header Information in WordPress

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This error, often seen as "Warning: Cannot modify header information - headers already sent", appears when your WordPress site outputs text before PHP sends the HTTP headers. It usually breaks page loading, login, or redirects. This guide walks you through the most common causes and fixes, from simple file edits to plugin conflicts.

What You'll Need

  • Access to your WordPress admin dashboard (if you can still log in).
  • FTP credentials or a file manager in your hosting control panel (cPanel, Plesk, etc.).
  • A plain text editor like Notepad++ or Sublime Text (not Word).
  • Basic familiarity with editing PHP files.

Step-by-Step

  1. Identify the exact file and line number. The full error message usually says something like headers already sent by (output started at /path/to/file.php:12). Note that path and line number—it's your biggest clue.
  2. Check for whitespace after the closing PHP tag. Open the file mentioned in the error (often wp-config.php, functions.php, or a plugin file) in your text editor. Look for any spaces, newlines, or blank lines after the closing ?> tag at the end of the file. If you see any, delete them and save the file. Many WordPress files don't need the closing tag at all—you can safely remove it.
  3. Check for a UTF-8 Byte Order Mark (BOM). If the file has a BOM (invisible characters at the start), it can cause this error. In your editor, re-save the file as UTF-8 without BOM.
  4. Edit wp-config.php carefully. Open wp-config.php in a text editor. Make sure there are no spaces or blank lines before the opening <?php tag. Also, remove any closing ?> tag at the end of the file if present.
  5. Check your theme's functions.php. Open /wp-content/themes/your-theme/functions.php. Look for any characters before <?php or after ?>. Even a single space after the closing tag can trigger the error. Remove any stray whitespace.
  6. Deactivate all plugins temporarily. If the error isn't file-specific, a plugin might be outputting content early. Rename the /wp-content/plugins/ folder to plugins_old via FTP or file manager. If the error goes away, one of your plugins is the culprit. Rename the folder back, then reactivate plugins one by one to find the bad one.
  7. Switch to a default theme. If plugins aren't the issue, your theme might be. Rename your active theme's folder in /wp-content/themes/ (e.g., yourtheme_old). WordPress will automatically fall back to a default theme. If the error disappears, your theme is the problem.
  8. Check for extra whitespace in plugin files. If you found a specific plugin, open its main PHP file and look for spaces before <?php or after ?>. Fix them or replace the plugin with a fresh download.
  9. Increase PHP memory limit (temporary workaround). Sometimes this error appears alongside memory exhaustion. Add this to wp-config.php just before the /* That's all, stop editing! */ line: define('WP_MEMORY_LIMIT', '256M');
  10. Check your .htaccess file. A corrupted .htaccess can cause issues. Go to Settings → Permalinks in your admin (if you can access it) and click "Save Changes" to regenerate the file. If you can't access admin, download .htaccess via FTP, open it, and look for any blank lines at the top or bottom.

Common Mistakes

  • Editing files with a rich text editor. Word or similar tools add hidden formatting characters that cause this exact problem. Always use a plain text editor.
  • Deleting the closing ?> tag incorrectly. If you remove it, make sure there's no whitespace left behind. It's safer to remove the tag and ensure the file ends immediately after the last PHP statement.
  • Not checking all files. The error may point to a file, but the actual issue could be in a file that's included earlier. Check wp-config.php, functions.php, and any file mentioned in the error message.
  • Forgetting to clear caches. After fixing the file, your browser or a caching plugin might still show the old error. Clear your browser cache and any WordPress cache plugins.

Tips

  • Always back up before editing. Download the file you're about to change so you can revert if something goes wrong.
  • Use a child theme. If you're modifying functions.php, use a child theme to avoid losing changes when the parent theme updates.
  • Enable WP_DEBUG. Add define('WP_DEBUG', true); to wp-config.php to see more detailed error messages that can help pinpoint the issue.
  • Check file permissions. Ensure your PHP files are readable by the server (usually 644 for files, 755 for directories). Incorrect permissions can cause odd behavior.
  • Update everything. Outdated themes and plugins are more likely to have coding errors. Keep WordPress core, themes, and plugins updated.

Troubleshooting

If the error persists after trying the steps above:

  • Re-check the exact error message. The file and line number may change after each fix. Follow the new path.
  • Check php.ini settings. Some hosts have output_buffering disabled. You can try adding @ini_set('output_buffering', 'On'); to wp-config.php (after the opening tag) as a temporary test.
  • Look for hidden characters in the entire file. Use a hex editor or a "show all characters" option in your text editor to spot invisible spaces or BOMs.
  • Test with a fresh WordPress install. If you're still stuck, download a fresh copy of WordPress, replace your wp-config.php and .htaccess with the originals (after backing up), and see if the error persists. If it does, the issue is in your theme or plugins.
  • Contact your hosting provider. If the error is in a server-level file (like php.ini), your host may need to adjust settings for you.

Frequently Asked Questions

Why does this error happen after I updated a plugin?

Updates can introduce coding errors or conflicts. The updated file might have a stray whitespace or a syntax error that wasn't there before. Reverting to the previous version or re-downloading the plugin from the repository often fixes it.

Can I ignore this warning if my site still works?

It's risky. The warning indicates a deeper problem that can lead to broken login, redirects, or a white screen. It's best to fix it even if the site appears functional.

I don't have FTP access. Can I fix this from the WordPress admin?

If you can still log in, go to Appearance → Theme File Editor and edit functions.php there. But be careful—a mistake can lock you out. Alternatively, use the file manager in your hosting control panel.

What if the error says "output started at wp-settings.php"?

This usually means a plugin or theme is loading too early. Try deactivating all plugins and switching to a default theme as described above.

Will adding output buffering fix it permanently?

No. It's a workaround that masks the problem. The underlying issue (stray whitespace or bad code) still exists and can cause other problems. Use it only temporarily while you find the real cause.

Is this error a security risk?

Not directly, but it can expose file paths in the error message, which could help an attacker. Fixing it also ensures your site runs smoothly and securely.