Home > Technology > Computer Science > Escaping a shortcode in WordPress

Escaping a shortcode in WordPress

Some people asked me how I managed to “escape” a shortcode in WordPress in the article I posted about the plugin “WM jqMath” – “How to use jqMath in WordPress“. So, I decided to write this small article about this subject.

In computer programming languages there are the “escape characters” to allow to enter reserved symbols. For instance, in JAVA language the double quotes (“”) are string delimiters. In order to be able to insert a double quote inside a string it is necessary to use a “escape character”.

Example:

String a = "How to insert a \"escape character\" inside a string";

Here, the symbol “\” is a escape character that allows us to put double quotes inside a string.

And in WordPress with shortcodes?

The oficial way to do it is by writing two square brackets within the shortcode. For instance: [[shortcode]] will display [shortcode].

In this case nothing would happen if we type [shortcode] because we don’t have any plugin that would render a shortcode named “shortcode”…

Now, to demonstrate how I escaped a valid shortcode, I’m going to use 3 square brackets on each side the shortcode in the post editor (the reader will see just 2):

[[jqmath expr="\$\$y={-b±√{b^2-4ac}}/{2a}\$\$" style="color: navy; font-size: 14pt"]]

But what the reader can see above is exactly what I wrote in the post editor to show the shortcode itself, with the result:

[jqmath expr="\$\$y={-b±√{b^2-4ac}}/{2a}\$\$" style="color: navy; font-size: 14pt"]

There are also people suggesting to use HTML code that will render these brackets:

  • [ for [
  • ] for ]

However, these codes will only work if you are editing your post in the “Text” view (HTML). I don’t recommend this solution because if you change the view from “Text” to “Visual” in your post editor, WordPress will change these codes to their respective symbols [ and ] and the post will render the shortcode.



Este artigo foi escrito de acordo com a antiga grafia.

About Carlos Santos

Frequency of master studies in Electrical and Computer Engineering. Freelancer developer (also works remotely): Websites, Web Applications (JAVA and PHP), J2SE/J2EE, C/C++ and Android. Private instructor and professional trainer in computer science and electrical engineering. Teaches in classrooms and remotely using Skype and Team Viewer. Interests: Music, audio, video, science, astronomy and mythology.

Leave a Reply

Your email address will not be published and it is optional.