How to display a shortcode without executing it

No matter which WordPress theme you are using, you must have come across at least one shortcode. Those little codes are a set of functions which allow developers to embed content into it so that users can easily get access to a specific content which they can display on their WordPress powered website.

Shortcodes are defined by the square brackets and a word/phrase in between them. Even if you’re not a fan of them, sooner or later you will start to love shortcodes and use them all over your website. Maybe you will start to write your own shortcodes in order to improve your site.

Probably one of the most popular is [gallery] shortcode which is used to display a gallery of images attached to a post.

While shortcodes can be placed practically anywhere on your site (yes, even in widgets) where you can execute them and show specific content (images, entire galleries, forms, videos, etc.), sometimes you will want to write about specific shortcode and display it as an example. So, if you are trying to display the shortcode itself, without executing it, you might have a problem. Because the shortcode you are writing about links to the function in the code, it will always execute.

If you have tried adding the shortcode into Visual Editor, you already know that it will execute no matter the editor you’re using.

So anytime you want to display the shortcode, you will need to escape the brackets symbols and therefore render the shortcode unusable. Don’t worry, there’s a really simple solution to it which you probably didn’t think about.  You can use one of the two methods in order to escape the brackets.

  • Type in double square brackets: [[shortcode]]
  • Replace the square bracket with its ASCII code: [ shortcode ]

 

Both methods will return a shortcode which will be displayed instead of executed. Pretty much simple as it gets, isn’t it?

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *