How do you stop a shortcode from firing in the editor?

I created a custom short code that includes creating an on page table along with a few other things. But the short code

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?

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?

Share Improve this question edited Aug 6, 2019 at 17:15 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Aug 6, 2019 at 12:39 fwhofwho 1091 gold badge2 silver badges11 bronze badges 4
  • Does your shortcode code echo its output or return it? It should return it. – Peter HvD Commented Aug 6, 2019 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 Commented Aug 6, 2019 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 Commented Aug 6, 2019 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 Commented Aug 6, 2019 at 14:21
Add a comment  | 

1 Answer 1

Reset to default 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;

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264133a4619349.html

相关推荐

  • How do you stop a shortcode from firing in the editor?

    I created a custom short code that includes creating an on page table along with a few other things. But the short code

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信