2
votes

I've a wordpress blog directly hosted from wordpress and I use the [code] tags to post sourcecode on wordpress, that works fine so far.

Thats the original code tag I posted

[code language="xml"]
 <TypeScriptTarget>ES5</TypeScriptTarget>
[/code]

But when I try to edit my posts with contained sourcecode it looks like this

new editet code

and when I update my post the same not encoded symbols are shown on my blogpost too. Id don't know what I am doing wrong here.

1

1 Answers

0
votes

First, you want to make sure the Visual Mode in WordPress is disabled, and only use Text Mode.

Users > Your Profile

Then you don't need to use a WordPress shortcode for adding a preformatted code block.

Check out the WordPress Codex Writing Code in Your Posts page:

https://codex.wordpress.org/Writing_Code_in_Your_Posts

Just use the HTML <pre> and <code> HTML tags:

 <pre><code>
    &lt;TypeScriptTarget&gt;ES5&lt;/TypeScriptTarget&gt;
 </pre></code>

You will notice I am using the HTML entity for the greater and less than symbols so they render correctly on the front-end of WordPress.

  • &lt; =   <
  • &gt; =   >

Resource links to the <pre> and <code> elements: