Shortcode problem (6 posts)

  1. Konstantin Kovshenin
    Posted 6 years ago #

    Hey all.

    I worked out a simple shortcode for templating but it seems that when I use it too much my post content becomes empty and this probably applies to all the shortcodes mechanism. I'm pretty sure it's not my shortcode function that's causing the glitch, because I added a die() command at the very beginning of my shortcode function and WordPress dies when content is small, but doesn't when it's too big. This means that it doesn't call the function at all.

    I'm not sure about how big the content should be, but I tried pasting [my-shortcode] [my-shortcode] [my-shortcode] etc for a few hundred times and BAM! No content. Now the strangest part of it is that if I add some text to my post at the very beginning before the shortcodes, it workes out! But then again, I add a few more hundred of shortcodes at the end and it dissapears again.

    Is this a WordPress glitch or what? Am I missing a limitation that hasn't been documented in the codex? It's not a recursion issue is it?

  2. Pinoy.ca
    Posted 6 years ago #

    Did you begin writing your shortcode function from the sample provided in the Codex, that is, extract, atts, $content and all?

    Is this an enclosure shortcode, like [url href="http://www.example.com"]Click me[/url]?

    Does your shortcode function use any global variables or call any WordPress built-in functions?

  3. Konstantin Kovshenin
    Posted 6 years ago #

    Hey Pinoy.ca, thanks for your time.

    My shortcode is so simple. Here's the code:

    add_shortcode('tpl', 'tpl_shortcode');
    function tpl_shortcode($atts, $content = null) { return $content; }

    I just ran a few more tests. Now if you input [tpl] [tpl] [tpl] 123 into a post and view it, you see 123. Then I input [tpl] a whole bunch of times and leave 123 at the end. Wordcount is approx 320. I save, preview the post and bam, no 123.

    Let's go further, I added 456 to the beginning of my post, so it looks like this 456 [tpl] ... (bunchload of tpls) ... [tpl] 123 and guess what, I preview the post and see 456 123! Strange, isn't it?

    Then I started adding more tpl shortcodes, works fine at the beginning. But when my word count reaches ~ 18000 it breaks and I see no text at all.

    P.S. PHP error messages are set to be outputted but I don't see any.

    Thanks for your help,
    ~ @kovshenin

  4. Pinoy.ca
    Posted 6 years ago #

    None of this is a recursion issue.

    If shortcode handler has a $content, it will be an enclosing shortcode. See http://codex.wordpress.org/Shortcode_API#Enclosing_vs_self-closing_shortcodes .

    Am I missing a limitation that hasn't been documented in the codex?

    Do you mean this one, http://codex.wordpress.org/Shortcode_API#Limitations ?

    Enclosing shortcodes cannot nest itself. And you are forgetting the closing tags.

    Please post again if something else isn't clear.

  5. Konstantin Kovshenin
    Posted 6 years ago #

    That doesn't seem to be the case. I post 123 [my-shortcode] [/my-shortcode] [my-shortcode] [/my-shortcode] 456 and it works fine, when I increase the shortcodes to 16k words I get an empty post. Though when I incraease that to over 100k words I get a php memory allocation error which I'm okay with.

  6. Konstantin Kovshenin
    Posted 6 years ago #

    One solution is to: remove_filter('the_content', 'wpautop'); Works fine now, but still strange :)

Topic Closed

This topic has been closed to new replies.

About this Topic