0

I created a custom short code that includes creating an on page table along with a few other things. But the short code is loading in the editor as well, and it is causing errors and preventing me from uploading the page. Is there a way to stop the short code from firing in the editor, or did I improperly code something?

enter image description here

  • Does your shortcode code echo its output or return it? It should return it. – Peter HvD Aug 6 at 13:53
  • It does echo it, but only because there is so much content. I build the entire table based on the mysqli results. That could very well be the cause though. – fwho Aug 6 at 14:03
  • 3
    Shortcodes must return their output, regardless of how much content there is. It's not a matter of convenience, it's how they work. For large amounts of content/HTML use ob_start() to capture output, and return ob_get_clean() to return the captured output. – Jacob Peattie Aug 6 at 14:07
  • I was worried about needing to break in and out of HTML a hundred times and trying to add it to a variable to return; but you dont need to with output buffering. Thanks @JacobPeattie, want to make an answer I can mark it? – fwho Aug 6 at 14:21
0

First follow what the codex says Shortcodes. Basically you just wrap your html in ob_start(); this will return the html as a string so you can echo it. 1st way :

function my_shortcode() {
ob_start();
?> <HTML> <here> ... <?php
return ob_get_clean();

}

2nd way

function my_shortcode() {
$output = '';
$output.= '<html>content</html>';
return $output;

}

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.