Escape Shortcode and Display as Syntax on Page or Post

By | May 19, 2014

WordPress comes with so many shortcodes to execute defined functions inside a page or post content area. but while writing a tutorial or documenting a WordPress product, we need to show the syntax of a shortcode and at that time, we do not want to execute that shortcode over there. Using image to show the shortcode is not a good idea as the visitor can not copy the text from an image. In this tutorial, I will show the way to escape the shortcode show that as a syntax.

[gallery link="file" columns="2" ids="813,814,815,816"]

1. Double wrap – Shortcode syntax starts with large open bracket and ends with closing bracket. If you use double brackets while opening and closing, that shortcode will appear as text and will not execute. For example, I have created a gallery with few images and now I like to show the syntax of that gallery, here is what I need to write on the editor,

[gallery link="file" columns="2" ids="813,814,815,816"]

and here is how it looks if used with single brackets,
Gallery visible in the site,

For opening and closing shortcodes, you just need to use double brackets once. For example,


2. Use HTML Entity – Rather than using the [ and ] brackets, you can use HTML entity counterpart for these brackets. For example,


It will be visible as below,


But the main problem with this technique is that if you change the layout from text to visual the formatting of HTML entity will be reset to normal brackets and will execute the shortode rather than showing that.

It is recommended to use the double brackets method to show the shortcode syntax.

Related Post

Category: Tutorials Tags:

About Sanjeev Mishra

I spend most of my time around WordPress and related plugins. It is almost impossible to resist myself from sharing good tips, tutorials and updates related to the platform. After all, I am a blogger by passion.