Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • muppix
    Participant

    I’m trying to use Shortcoder in conjunction with WordPress tables and have two uses cases, both of which fail when I use the [/sc] tag:

    1. Provide a central edit point for widely dispersed information
    2. Allow styling to be applied beyond WordPress UI

    Both use cases related to fixtures lists on our website, which inform visitors of upcoming events via tables, one per month.

    The first use case lets us show seasonal opening hours for different days, and I’m using [sc name="winter-hours-wed"] to show the hours for Wednesdays, with similar Shortcodes for other days of the week.

    Block editor screen grab

    Rendered Result

    This only seems to work if I omit the closing [/sc] tag – as soon as I add it the table becomes broken, as if some of the HTML is being removed server-side.

    Block editor screen grab

    Rendered Result

    Web Inspector

    We can see in this case that the <tr> containing the [/sc] closing tag has been removed server-side, as if an error has occurred and WordPress is trimming out the enclosing tag in order to protect the rest of the table. (It’s not always the <tr> that gets removed, sometimes it’s the enclosing <td>, but you get the idea – the only way for me to use Shortcoder in a table is to omit the [/sc] closing tag)

    My second use case is intended to let editors apply styling to selected content within a table cell without editing the whole table in HTML mode, which is the only alternative since WordPress doesn’t provide such controls in their editor UI. I’ve therefore created the following Shortcode to wrap enclosed content with an element, which is styled via custom CSS:

    Shortcode detail

    Block editor screen grab

    Rendered Result

    Here we can see that again row #5 has been removed, and this time the last cell from the preceding row is also gone. For this use case there is no workaround, since I need the closing [/sc] tag in order to wrap the Shortcode around my content.

    In closing, I appreciate that the use of Shortcoder inside tables is possibly an edge case not worthy of the developer’s immediate bandwidth, in which case I’d be happy with some pointers for debugging the issue myself. Either way please do let me know if there’s anything I can do to help.

    Hi @muppix,

    Thanks for using Shortcoder.

    The issue you are facing is a known behavior.
    All shortcoder’s shortcode must be “closed” with [/sc] otherwise WordPress cannot differentiate when a shortcode is opened and closed.

    This is one of limiatation of the Shortcode API. Read more here – https://codex.wordpress.org/Shortcode_API#Unclosed_Shortcodes

    But the solution is very simple, please close all the shortcodes [/sc].

    If you have a mix of open and closed shortcodes then WordPress parser will misinterpret.

    Thanks,
    Aakash

    muppix
    Participant

    Thanks @Akash – I now understand that all shortcodes on a page must be closed, and having implemented that change can confirm that it works as expected. I think this goes back to a time before Shortcoder was able to use enclosed content and therefore did not use closing tags, but my memory’s not that good so I’ll just say thanks for the helpful response. 😁

    Incidentally, I’m sorry all of the images in my original post are broken. I used the image upload service that was linked from the New Topic page, and the separate IMG sources do work when used in isolation, but just not when embedded in a post.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Subscribe for updates

Get updates on the WordPress plugins, tips and tricks to enhance your WordPress experience. No spam. View newsletter