Shortcode makes WordPress easier to use if you want to call a defined function in page or post. What if suppose you added a snippet to just display the shortcode text snippet but it got executed due to function call ?
When you add a shortcode snippet, WordPress automatically call the function assigned with that particular short. Hence, to tackle with problem of shortcode execution instead of display there are two simple methods to do.
1. Adding [ ] around shortcode snippet.
This is easiest way to display the shortcode in WordPress. Suppose you have some shortcode as [example] and you want to display the shortcode in text instead of executing, then add square brackets around it [[example]].
How this works ?
When you add simple shortcode in WordPress [example], then WordPress will check the square brackets first and execute the function mentioned in brackets i.e. example.
Now when you add double brackets around a shortcode [[example]], then WordPress again try to check for function in first bracket itself i.e. [example]. But now is second case, as we do not have any function name as [example] WordPress just return the text without executing.
2. Using HTML reference for [ ].
Using HTML references for square brackets is another method to stop execution of function in shortcode. If we add the HTML reference text instead of square brackets, WordPres doesn’t call any function. But in HTML page, reference will be displayed as bracket.
Following are reference code that will be used for shortcode display:
- [ for open square bracket [
- ] for close square bracket ]
Example: [example] will be displayed as [ example ] in webpage.
Note: You need to add these reference code only in text editor of WordPress not in visual editor. Adding in visual editor will consider it was alphabets and special characters.