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 ?>

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *