error on line 1 at column 6: XML declaration allowed only at the start of the document
If you’re having issues with your WordPress feed, the solution could be rather simple. It seems that this issue is often caused by white space characters at the end of php files. This is deceiving however. In my functions.php file I didn’t have white space at the end of my file AFTER the “?>” closing php tag. This was driving me insane because everything I had read stated that white space is the issue! It was indeed the issue, but it was trickier than that.
How did I solve my issue?
I deleted the ending php tag and made sure there were no spaces, returns, etc after the last character in my php code.
My issue was in my functions.php theme file, however you issue may be in a different file. If it’s not in your functions.php file, check elsewhere.
So why does this happen?
This happens because of the output buffering. It took me quite some time to locate the issue, but this statement is where I drew my conclusion.
“If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.”