最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览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?

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;

}

发布评论

评论列表(0)

  1. 暂无评论