Rantiev
Rantiev

Reputation: 2242

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 (

[[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.

Upvotes: 1

Views: 997

Answers (2)

Павел Иванов
Павел Иванов

Reputation: 1154

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]]

Upvotes: 1

KernelCurry
KernelCurry

Reputation: 1297

the Answer: replacing [ by [ and ] by ]

Link: https://wordpress.stackexchange.com/questions/33960/how-do-i-escape-a-in-a-short-code

Side Note:

Wysiwyg <=> text transition causing html encoding is, and always be a problem. I would recommend just getting rig of the visual editor all together!

Upvotes: 0

Related Questions