Show shortcodes on your site without activating them

Show shortcodes on your site without activating them

Have you ever needed to show a shortcode on your WordPress website, possibly in a tutorial? Inserting a shortcode into the contents of your WordPress page or post will cause that shortcode to be activated when shown on the front end, the shortcode will be replaced by whatever text/data that shortcode creates and you won’t actually see the shortcode embed code itself.

Tricks using html codes to create the brackets, etc, don’t always work because the WordPress editor auto changes those codes to the text equivalent.

So whats the answer?

Another shortcode of course! We created a quick shortcode to do just this for use on our own site to allow us to show how to use our Machform Shortcode and other items that we are working on.

Add this to your functions.php inside of your theme:

function showshortcodes($atts, $content = ''){
        // Return the content without processing any shortcodes inside of it
        return $content;
add_shortcode( 'showshortcodes', 'showshortcodes' );

Using this shortcode is easy, whenever you want to show a shortcode on your site, you simply wrap it in our new shortcode. So lets say you have a shortcode called [coolshortcode] and you want to demo that on your site, here is how you could do that:

[showshortcodes][coolshortcode option="value"][/showshortcodes]

Its simple, but it is effective and it works.

If anyone desires to use this but you don’t feel confident editing your theme files, let us know, we’ll create a plugin that adds the shortcode that you can easily add to your WordPress site.