Display Shortcodes in WordPress without Executing Them

WordPress provides you with shortcodes that let you do nifty things with very little effort.

Shortcodes can embed files or create objects that would normally require lots of complicated, ugly code in just one line.

Lately we were writing an article in which we wanted to display a shortcode but unexpectedly the shortcode got executed instead of simply showing up.

Below are the 3 options from our developer that you can use to display the shortocde without rendering it on the front-end:

Option 1. Wrap shortcode in square brackets

The structure of WordPress shortcodes is enveloped by an opening and closing square bracket [shortcode_name].

If you write the shortcode as it is and it is already present in the WordPress Shortcode library then surely it will get executed.

So to stop its execution, wrap it in square brackets like in the example given below:


Any shortcodes that are wrapped in square brackets will be displayed on the front-end of your site, but will not be executed.

Option 2. Use <code> tag inside the square brackets

WordPress executes the shortcode only when it's in its right format.

In the above option, we disturbed the square brackets, in this option we will disturb the inside part of the brackets by wrapping the content with <code></code>

Below is how it should look:


The code container HTML tag will create a barrier between shortcode content and square brackets, and ruin the shortcode's format.

A shortcode with ruined format won't execute and we will be able to acheive our task.

Option 3. Replace square brackets with HTML codes

If you replace square brackets with the HTML code for those brackets, then WordPress will render the HTML output on the frontend, instead of rendering the entire shortcode.

So, if you want to use [shortcode], use &#91;shortcode&#91; instead.

You have to add it to the Text/HTML Editor of the WordPress editor.

But here's the problem, as soon as you switch back to Visual Editor, WordPress will turn the HTML back to its rendered form.

Hence, this option is not suitable for most people.

I hope the above 2 methods helped you display shortcodes with no execution. If you have any doubts or other ways to share then feel free to use the comments section below.