Can't set cookie in Wordpress plugin after theme has started rendering

前端 未结 2 839
野性不改
野性不改 2021-01-25 17:22

When I set a cookie in a Wordpress plugin, I get the \"headers already sent\" error. Can someone suggest how I can fix this?

Warning: Cannot modify header

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-25 17:30

    You're calling your set_cookies function too late. At the time you call it, output has already started. You need call it before any output has started, because cookies can not be set if output has already started (see as well: setcookieDocs).

    In your case before header.php line 11 is being executed.

    That's merely before the theme get's loaded.

提交回复
热议问题