How to Prevent WordPress From Executing Shortcode in Post

WordPress shortcode

Two days ago, we published an awesome article about using Genesis Framework shortcode to customize Genesis child themes. On of the difficulties we had was preventing the shortcode from being executed when we include it in the body of the post. Since we’re using Genesis Framework, any Genesis shortcode that we put in the body of the post will be executed. Therefore, we need to find a way to prevent any shortcode from being executed in the body of a post.

Luckily, the solution to this is dead simple. If you open wp-includes/shortcodes.php file, you’ll find this chunk of code:

The code above was copied from line 191 t0 247 from the file (as of WordPress 3.8.1).

If you’ve no idea what the code is doing, freat not. WordPress does everything for you. In line 11 and 16, you’ll see these comments:

An extra [ to allow for escaping shortcodes with double [[]]
An extra ] to allow for escaping shortcodes with double [[]]

Solution:

There’s no additional code or plugin need to be added to your site.

Whenever you want to post a shortcode and do not want it to be executed, simply wrap it with with double [ and ]. From example, [[this_is_my_shortcode]].

That’s all you need to do. We hope this tutorial helped you out. This is a very basic thing you need to know, especially when you publish many WordPress tutorials like us.

Comments

  1. This is super cool stuff. I would have never thought to just change it to double brackets. Sometimes the simplest solution is the best solution. Thanks.

  2. Hi wpspeak, you must just love coding you’re always deep into the code with your posts! I’ve always wanted to start coding but it’s really hard to learn everything.

Leave a Comment

*