• Resolved MDN2014

    (@mdn2014)


    I just updated my Yoast plugin to version 5.0.2 on a WordPress install running 4.8., and I noticed a change in functionality.

    I have several custom shortcodes defined in my functions.php file. When I edit a page that has these shortcodes and I hit the “Update” button, the /wp-admin/post.php page reloads. Instead of the WordPress post editor reloading, I get a plain white page with my rendered content (no editor), followed by an error as follows…

    Warning: Cannot modify header information – headers already sent by (output started at /[home directory url omitted]/functions.php:548) in /[home directory url omitted]/wp-admin/post.php on line 197

    Line # 548 in my functions.php file is the location of the shortcode definition.

    I didn’t have this issue before the update. When I turn off the Yoast plugin, it goes away and everything functions normally. This conflict appears to be limited to editing a page.

    Let me know if you need further info.

Viewing 4 replies - 1 through 4 (of 4 total)
  • This issue typically occurs when the custom shortcodes function isn’t defined correctly. Can you please share the relevant shortcodes function that you have added to your theme functions.php file so that we can take a look?

    Thread Starter MDN2014

    (@mdn2014)

    Hello,

    Sorry for the long delay in the response—the notification fell into my spam folder and I just now found it!

    Here’s an example of a shortcode that breaks. Please do let me know how I might edit it to solve this problem….

    function make_quiz_item($params, $content = null) {
    $current_item = $_GET[‘step’];
    $this_item = $params[‘tag’];

    // Set default
    if (! strlen($current_item)) { $current_item = “q1”; }

    if ($this_item == $current_item) {
    echo $content;
    }
    }

    add_shortcode(‘quiz-item’, ‘make_quiz_item’);

    Many thanks!

    Thread Starter MDN2014

    (@mdn2014)

    Hello Mazedul,

    Just a follow-up on this issue. I updated to the latest Yoast (5.1) and I’m still seeing the issue. Can you tell me how I’m incorrectly defining the shortcode? I’ve tried looking up documentation on creating custom shortcodes, but everything I see indicates it’s as simple as defining a custom function and using the add_shortcode function. My functions.php file is in a child theme. I hope to hear from you (or anyone who might have an answer to this issue).

    Many thanks!

    Thread Starter MDN2014

    (@mdn2014)

    Just a follow-up: I think I figured it out. I’ll post the solution I arrived at here, just in case anyone else has the same issue.

    Apparently I need to add the functions ob_start(); and return ob_get_clean(); within my shortcode function like so….

    function make_quiz_item($params, $content = null) {
    ob_start();
    $current_item = $_GET[‘step’];
    $this_item = $params[‘tag’];

    // Set default
    if (! strlen($current_item)) { $current_item = “q1”; }

    if ($this_item == $current_item) {
    echo $content;
    }
    return ob_get_clean();
    }

    add_shortcode(‘quiz-item’, ‘make_quiz_item’);

    After I did that, the shortcodes behaved normally when I edit a page with them. FYI to anyone else who runs into this same problem!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Shortcode functionality break after 5.0.2 update’ is closed to new replies.