Display WordPress shortcode without it executing

WordPress plugins and themes often come with built-in shortcodes. Using them is usually straightforward, and, until just recently, I thought displaying one in a post (i.e. [imashortcode]) was not so straightforward.

The first thing I noticed when I tried to document my first plugin that I had activated on my site was when I typed the shortcode it was executed instead of displaying the shortcode text. Well, duh. That’s what they are supposed to do, right? The solution was quite elegant and much easier than I thought it would.

A shortcode is normally written with a single set of square brackets around it. Like so…

[imashortcode]

However, just typing that will get you an executed shortcode. The solution is to wrap the shortcode in another set of square brackets like so…

[[imashortcode]]

Posted in Tech Tagged with: ,

Leave a Reply