Support » Fixing WordPress » Headers already sent in REST API endpoint since 5.6x

  • Resolved joho68


    Serving images via a WP REST API endpoint, I came across something that I cannot quite put my finger on. All of a sudden, without any other changes, I’m getting:

    [09-Feb-2021 13:59:06 UTC] PHP Warning: Cannot modify header information – headers already sent by (output started at /home/html/ in /home/html/ on line 1631

    I’m sure there’s something I’m doing wrong, but did something change in WordPress Core/REST between 5.4x and 5.6x? Nothing has changed in the code for ‘myplugin’. Looking at the code it points to (in myplugin), I do indeed issue header() calls, followed by ob_start(), echo blablabla, and ob_endflush().

    I have checked for possible whitespace in places like functions.php, etc. but haven’t found anything.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve seen the error several times before. It usually occurs when a plugin or theme has either a PHP error or is being verbose and outputting something it shouldn’t. Did you maybe add some code to your header. If so look to make sure it ok. It almost always some kind of coding error.

    Thread Starter joho68


    Thanks for responding. I’m aware of these potential issues, but AFAIK, nothing has changed in the plugins involved, and certainly nothing in my own plugin. But I “solved” this by issuing an exit-call in my REST handler (which does the output) as opposed to returning a value. So that’ll have to do for now.

    (Another option would, of course, have been to simply have a .php file outside of WordPress’ REST framework.)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Headers already sent in REST API endpoint since 5.6x’ is closed to new replies.