18

I am trying to display code in my WordPress page and it isn't working. Everything I read says that you should be able to just use pre tag with code tag and it would be good but when I try to display a shortcode, it renders the shortcode rather than displaying the code.

The codex says that using pre and code would work but it isn't for me. Has anyone had this issue? Am I missing something in functions.php that makes this work?

25

To display a shortcode instead of rendering it you have two options:

  1. Write [[shortcode]]. WordPress will show this as [shortcode].
  2. Escape the [, write it as as [ or [.
  • Hi, mmy problem with the [shortcode] is that each time I edit the page they are changed to brackets characters..BTW, the 1st solution works fine for me – 538ROMEO Feb 1 '17 at 13:31
  • If you have a shorcode with content, put the extra brackets around the whole shortcode, not the beginning and end tags, ie [[shortcode]content goes here[/shortcode]] – SteJ Jan 8 at 18:20
3

Worked for me: [shortcode] where &#91 is [ and ] is ] html codes.

Don't worked for me the one suggested by toscho: Write [[shortcode]]. WordPress will show this as [shortcode].

3

Using &#91 tag will not work if you switch between the text and visual editor.

The [[shortcode]] solution does not work either with WP 4.1.1.

Instead, the following solution works:

[[shortcode]
Hello World
[/shortcode]]
3

I tried all suggested answers, none worked for me.

Here is my (strange) way of showing [solr_search_shortcode]:
<pre>[<code>solr_search_shortcode</code>]</pre>

See it live here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.