admin管理员组文章数量:1130349
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)
- This is a great solution, thank you @jypweb! You might want to change your question to only contain the question, and then move your "after" code to your answer. This should help future users find the answer easier (by looking below) and understand the problem better (by looking at the question) – skplunkerin Commented Oct 5, 2017 at 15:43
1 Answer
Reset to default 1The 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.
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)
- This is a great solution, thank you @jypweb! You might want to change your question to only contain the question, and then move your "after" code to your answer. This should help future users find the answer easier (by looking below) and understand the problem better (by looking at the question) – skplunkerin Commented Oct 5, 2017 at 15:43
1 Answer
Reset to default 1The 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.
本文标签: shortcodeWordpress Yoast SEO plugin Post SaveUpdate Issue
版权声明:本文标题:shortcode - Wordpress Yoast SEO plugin Post SaveUpdate Issue 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749156470a2324677.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论