WooCommerce: How to Write Shortcodes Without Outputting Content?

When I write tutorials like WooCommerce Separate Login & Registration Pages I often need to “write” on the screen the actual shortcode – but I don’t want the shortcode to output content!

For example, if I write [woocommerce_my_account] it’s guaranteed you won’t see “[woocommerce_my_account]“… you will see Business Bloomer’s My Account page content instead!

So there is a great workaround for those of you who write tutorials, snippets and WordPress articles and need to print the actual shortcode on the screen, without making it “process” its content and outputting it.

Enjoy!

Use double square-brackets instead of single ones

I searched online and actually found a very neat way to “write” shortcodes, without messing up with the output.

The great news is that the reader won’t see them: the output will have single square-brackets, but the shortcode won’t output the content.

If you want to “print” a shortcode on the screen (and this is valid for ANY EXISTING WordPress and third party plugin & theme shortcodes), use:


[[my_shortcode]]

Once you write that in the WordPress content editor, you will see this on the screen:

[my_shortcode]

If the shortcode does not exist, the screen will feature double quotes, as there is nothing to output:

[[my_shortcode]]

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Leave a Reply

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