WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
Thank you for you answer. In my question, I forgot to put ']' in a code block so it came out as a ']'. I've edited my question. The HTML entity works for WP, but not for Google Maps. I'll have to use Regex to replace the HTML entities. Thank you very much for the help. – Laxmidi Nov 17 '11 at 17:47
@Laxmidi My above "guess" that there is no escape character borders on certainty - just wanted to be cautious to not provide misinformation. If there was, I'm positive the codex article on the Shortcode API would mention it. I think replacing afterwards is your best bet. Do you need a regex for one character though? I think str_replace() should get the job done as well. Would be less resource intensive, if it did. – Johannes Pille Nov 17 '11 at 17:55
@JohannesPille hello it's an oldie, but i need to have the [ ] also replaced by ]. First time saving in WP and it works, but when editing the post/page WP turns ] into ]. (need this for a google event tracking on shortcode buttons) regards – alex Oct 18 '13 at 6:31

This is an old question, but here's a workaround using css. In place of braces, enclose characters in a span, like so:

<span class="bracket">some string</span>

then, add this to the theme stylesheet:

span.bracket:before {
  content: '['
.colored-blocks span.bracket:after {
  content: ']'

the result will look like this:

[some string]

share|improve this answer
The question is about inserting ]as part of the content, not about how to display it. – Mark Kaplun Apr 12 at 11:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.