Wordpress - How do I escape a ']' in a short code?

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.


There seems to be an official page here : Escaping Shortcodes

Extract :

To do this, you need to escape the shortcode by using two sets of brackets instead of just one. So to display this in your post:

[gallery]

You would write this:

[[gallery]]


Based on the Johannes Pille's answer there is wp function to escape square brackets for using text in shortcode parameters:

function my_esc_brackets($text = ''){
    return str_replace( [ "[" , "]" ] , [ "[" , "]" ] , $text );
}

Often people suggest using shortcode's $content for text parameters, but there are cases when the shortcode has many such text parameters.

Tags:

Shortcode