Full example of the error message

Warning: session_start(): Cannot send session cookie – headers already sent by (output started at /home/mysitename/public_html/wp-content/themes/theme-child/functions-myfile.php1:328) in /home/ mysitename /public_html/wp-content/themes/ theme -child/functions- myfile2.php on line 711

There’s a good explanation of this issue here: https://wordpress.stackexchange.com/questions/324762/setting-cookie-with-init-hook-causes-header-already-sent

Basically is simply that you mustn’t have any whitespace after the closing ?> of your themes php files, as theme and plugin files are loaded before init is called by wordpress, and init is what is best used for the session_start() call.

session_start() must be the first thing, before any whitespace even. You can’t set cookies, or send any other headers, if any of the content of the site is already sent.

In the example above functions-myfile.php1 is the file with the issue, line 328 is a blank line after it closing ?>

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.