Escaping multiline wordpress shortcodes

How to escape multiline wordpress shortcode?

[accordion_item title="Item 2"]
item content
[/accordion_item]

We could use double brakets, but “/” sign brokes everything. Can’t belive WP guys lost this case (

Read More
[[accordion_item title="Item 3"]]
item content
[[accordion_item]]

this works, but code below doesn’t escaped properly

[[accordion_item title="Item 3"]]
item content
[[/accordion_item]]

Don’t want to replace manually brakets with html codes. (and WP automatically get them back after user switch editor mode to visual)

Thanks in advance.

Related posts

Leave a Reply

2 comments

  1. Function get_shortcode_regex() in shortcodes.php makes all logic with escaping shortcodes parsing (capture group 1 and 5)

    For example with

    [[new_something my_attr="test"]And have content!! [vc_tabs][/vc_tabs][/new_something]]

    After preg_match_all you will get that
    first capture group is not empty and it is “[” (so you can know that this shortcode is not for rendering)

    second capture group will show shortcode name “new_something”

    third capture group will show everything in attributes " my_attr="test""

    four capture group will show content And have content!! [vc_tabs][/vc_tabs]

    Five capture group will show that escape characters has at end.

    Basically this means that all information is known when you write escape like this: [[your_shortcode]content[/your_shortcode]]