$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>shortcode - Wordpress Yoast SEO plugin Post SaveUpdate Issue|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

shortcode - Wordpress Yoast SEO plugin Post SaveUpdate Issue

matteradmin11PV0评论

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)

Share Improve this question edited Oct 5, 2017 at 17:35 jypweb asked Oct 5, 2017 at 9:21 jypwebjypweb 214 bronze badges 1
  • 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
Add a comment  | 

1 Answer 1

Reset to default 1

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.

Post a comment

comment list (0)

  1. No comments so far