The Problem
Whenever the Yoast Premium SEO plugin is active, posts are unable to save/update properly in the Admin Menu. After hitting the Update button, I found that all the custom theme shortcodes within the post were being rendered (without the CSS) instead of me being returned to the post editor. With debugger enabled, I was receiving errors like:
Cannot modify header information – headers already sent by (some/file.php)
The Problem
Whenever the Yoast Premium SEO plugin is active, posts are unable to save/update properly in the Admin Menu. After hitting the Update button, I found that all the custom theme shortcodes within the post were being rendered (without the CSS) instead of me being returned to the post editor. With debugger enabled, I was receiving errors like:
Cannot modify header information – headers already sent by (some/file.php)
The Solution
After WAY more research than I cared for and ultimately not getting a straight answer, I started to realize that the custom shortcode I was using to create HTML might be to blame. I was creating content by closing the <?php
tag and reopening it after the html was finished. Turns out, I should have been using an output buffer like ob_start()
/ob_get_clean()
and returning the code instead.
Before:
if (argument > 0) {
?>
<p>Some text</p>
<?php
}
After:
if (argument > 0) {
ob_start();
?>
<p>Some text</p>
<?php
return ob_get_clean();
}
This returns the buffered HTML and allows any filters or echos to take place on the shortcode properly. Once this change was made, Yoast (and a couple others like Relevanssi) started working as they were intended to.
Now it's possible that you might get the same debug errors for other reasons, but in this instance, it boiled down to my custom theme not producing shortcodes correctly.