Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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!

    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)

    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!

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