Skip Navigation

Shortcodes in conditionally displayed content may not be executed on the front-end

Won't fix

Reported for: Toolset Views 2.8.3

Symptoms

When an HTML Conditional is used to display or hide content, and that conditionally-shown content exceeds (together with the HTML Conditional itself) a certain amount of characters, then shortcodes within that HTML Condition will not execute anymore.

This means your shortcodes that are shown conditionally may just be printed as shortcodes instead of rendering their content.

The number of characters needed in the conditional until the shortcodes are not executed anymore depends on the PHP version:

  • For PHP 5.+ it is around 2344 characters
  • For PHP 7.+ it is around 2667 characters
  • For PHP 7.3.x it is around 7873 characters

Workaround

The language (PHP) in which most of WordPress and Views are written has a limit of the length it can take for a given feature. This is a limitation of the platform that Toolset cannot solve. In this case the pcre.jit limit is reached.

However, we do have plans to allow solutions (workarounds) to this limitation, which will eventually be part of future Toolset (Access) Releases, by passing entire Content Templates to Toolset Access shortcodes as an input source.

Until then you can simply use fewer characters within the same condition, to resolve the PHP limitation.

11 thought on Shortcodes in conditionally displayed content may not be executed on the front-end

  • Yes, this is a good explanation. However, I would add that the content within the conditional can simply be split up into two or more conditionals so that the maximum character count is not exceeded.

  • Hi, I think I triggered this bug. I have a template for a custom post type. Some posts are displayed correctly, some others display the shortcodes. I have one doubt: can you confirm that when this limit is reached for one conditional block, ALL the conditional blocks on the page stops working? This is what it seems to happen for me.

    • No, the issue here is that if the amount is exceeded, meaning when an HTML Conditional is used to display or hide content, and that conditionally-shown content exceeds (together with the HTML Conditional itself) a certain amount of characters, then shortcodes within that HTML Condition will not execute anymore.

      Other code proceeds to work unless I miss something not yet known

      It’s actually simple to test.
      Do you have more than ca. 2k characters in that condition?
      Is the issue totally resolved if simply splitting that condition into 2 parts?
      If both answers are yes, the issue is the same, if no, then not – in this case, a new ticket is required.

      Thanks!

      • Hi, I made this test:
        – page with 8 different conditional blocks (not nested);

        If one of the blocs exceed the number of characters:
        – all blocks inside every conditional blocks (even those that doesn’t exceed) are not rendered, and shortcakes are displayed;
        – other blocks not inside a conditional block are rendered correctly

        NOTE: the block that exceed contains a repeating field, so I was able to test that on pages where this field had 2 or 3 instances everything was ok, in pages with 10-15 instances of this field, where the 2k limit was exceeded, no conditional field was working .

        • Blocks is different. Yes, when just ONE thing breaks in a blocks environment (Gutenberg) then everything will break, you will not be able to save the post eve, depending on the error

          In any case if you can confirm with a lower than exceeding amount of characters the issue is resolved, you have no other option but to split those conditions.

          • Hi, luckily I was able to solve the problem without using conditional blocks, but in this case I think it will be tricky to split the condition: indeed it was a very simple conditional bock that displayed it content if one condition was meet. But the content is a repeating field, so I should put another condition inside for splitting this fields based on their number.
            Anyway this article was useful: it is the first you find in Google looking for this problem, and knowing that there is a limitation is useful for not becoming crazy looking for other bugs 🙂

            • Wow, this scenario actually escaped me… Thanks for adding it
              I updated our issue tracker so it is clear that this might be an issue with relatively simple (large, but simple) output already

  • I ran into this back in Nov/Dec 2019, and suggested an errata be added somewhere. At that point, I was able to split the conditionals with little trouble. I just now ran into it again and I am building a table within several nested conditionals, so it will be more difficult to split.

    However, I have the same site loaded on a different server and it works. After debuggin for 2 days, I noticed that other server is running PHP 7.3.x and my live site is running 7.2.x. I was skeptical that was the problem and didn’t want to chance bumping the live site to 7.3.
    But… I see at the top of this errata description, it shows the character limit for PHP versions 5.x, 7+ and 7.3. I think this means the difference between 7.2.x and 7.3.x goes from 2667 characters to 7873!

    So, off I go to upgrade the live site to 7.3, and expect (and hope) that will take care of it.

    And just to confirm, if you have 1 block of nested wpv-conditionals, and the outermost (top) conditional contains too many characters, all wpv-conditional shortcodes on the page stop working.

    Jeff
    –––––––

    • Hi Jeff. Yes, PHP versions have different limits but note those limits are rather arbitrary also determined by your current machine hosting the site.

      The error will break any conditional that has too long content “in total”, but other conditions on the same page (but outside the failing condition) shouldn’t fail.

  • Hi Beda –

    I have many sections (not to confuse with Guttenberg Blocks) of conditionals on my Event page, which is a single page content template, handling events of many different types. If one of those sections exceeds the character limit, all following sections in the template – even if they are not (inside) the exceeding block, appear to fail. I repeated this as a test several times because it didn’t make sense to me. But in fact, this seems to be the case. Conditional sections above the exceeding block are not affected and are rendered correctly.

    • Oops!
      I forgot to mention, I upgraded the live site to PHP 7.3 last night, and it fixes the problem as I had expected. A note in the errata to emphasize the capability of this in 7.3 might be helpful to others.

Leave
a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>