To write a WordPress shortcode without it outputting content — for example when writing documentation that needs to literally display [my_shortcode] on the page — wrap it in an extra pair of square brackets, like [[my_shortcode]], and WordPress will print it as plain text with only the outer brackets stripped.
Why You’d Need to “Escape” a Shortcode
- Writing tutorials or documentation about shortcodes normally triggers WordPress to actually execute them
- Without escaping, a shortcode mentioned in an article renders its real output instead of showing the code itself
- This built-in WordPress escaping mechanism avoids needing separate plugins or manual HTML entity tricks
The Escaping Technique
[[my_shortcode]]Type this directly into the WordPress content editor. On the published page, it will display as:
[my_shortcode]WordPress recognizes the doubled brackets as an instruction to print the shortcode literally rather than execute it, stripping only the outer pair.
What Happens With a Shortcode That Doesn’t Exist
If the shortcode inside the double brackets isn’t actually registered anywhere on the site, WordPress will display the full double-bracket text as-is, since there’s nothing valid to process or strip.
Troubleshooting
The Shortcode Still Executes Instead of Displaying as Text
Confirm you’re using double square brackets on both the opening and closing tag consistently — a mismatched single/double bracket pair won’t trigger the escaping behavior correctly.
The Technique Doesn’t Work Inside a Code Block or Preformatted Text
If you’re already displaying the shortcode inside a <pre> or <code> tag, WordPress typically won’t process shortcodes there at all — the double-bracket trick is specifically for shortcodes written as regular paragraph content in the editor.
Frequently Asked Questions
Does this work for shortcodes with attributes too?
Yes — you can escape a shortcode with attributes the same way, e.g. [gallery ids="1,2,3"] will display literally rather than rendering an actual gallery.
Does this work in the block editor as well as the classic editor?
Yes — the underlying WordPress shortcode escaping mechanism applies regardless of which editor generated the content, as long as it’s rendered through the standard content filter.
Is there an alternative to double brackets for displaying shortcode text?
Yes — manually HTML-encoding the brackets ([ and ]) also works, though the double-bracket method is simpler to type directly in the editor.
Conclusion
Writing a WordPress shortcode without it outputting content is as simple as wrapping it in an extra pair of square brackets — a small, built-in WordPress trick that’s especially handy for anyone documenting shortcodes, snippets, or tutorials.
See also How to Count Product Purchases by ID With a Shortcode. Then read How to Display All Products Purchased by a Customer in WooCommerce.
Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.