0

I am trying to create a really simple plugin that creates a really simple shortcode, but when I insert the shortcode in the editor, and try to save the page I get the following error: "Updating failed. The response is not a valid JSON response."

I think the shortcode is being executed in the editor, because if I delete the shortcode there is no error, and I can see the echoed text for a second, when I opening the editor.

this is my plugin content:

<?php

/**
 * Plugin Name: test plugin shorcode
 */

function vbshort_shortcode() {
    echo 'Hello shotcode!';
}

add_shortcode('vbshort', 'vbshort_shortcode');

1

From the add_shortcode() docs:

Note that the function called by the shortcode should never produce an output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results.

Your code should be:

function vbshort_shortcode() {
    return 'Hello shotcode!';
}

add_shortcode('vbshort', 'vbshort_shortcode');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.