How do I escape a right bracket in a short code?
I’m working on a Google Map plugin that has encoded points. Sometimes the polygons have the ] in it, which makes WP think that it’s the end of the shortcode.
For example:
[my_shortcode latitude="36.93" longitude="-72.98" encoded_points="ortlF~g]tM?cZEH`z]}|@DQfi]" ]
I’ve tried ]
which is isn’t causing a problem for WP, but it is causing a problem for my Google map code. I could use Regex to replace ], but maybe there is a simpler way. Does shortcode have an escape character?
I don’t know of an official escape syntax for shortcodes and there likely isn’t one.
When wordpress parses for shortcodes it looks for [ and ]. If you want to use square brackets within a shortcode, using the respective html ASCII entities escapes them.
I.e. replacing [ by [
and ] by ]
. WordPress will not recognize ]
as the end of the shortcode.
Whether that serves your purpose obviously depends on whether it gets converted to ] before being passed to the Google Maps API or whether the API handles it as expected. I have no experience with that, so can’t say.