admin管理员组

文章数量:1316588

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?

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?

Share Improve this question edited Sep 9, 2012 at 5:45 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Sep 9, 2012 at 5:35 JamieJamie 1,3635 gold badges25 silver badges47 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 30

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 [.

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]]

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].

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.

Wrapping brackets with <span>[</span> also seems to work

本文标签: Show shortcode without executing it