• I just want to post the contents of an XML file I wrote, but WordPress is expectedly interpreting it as HTML and is just displaying the contents of the elements without the elements themselves. Can I tell WordPress to escape the XML somehow, or is there a HTML element that will do this for me?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You need to encode the opening < and closing > characters in your sample markup. So:

    <label for="s">Keyword(s)</label> <input class="text" type="text" value="" name="s" id="s" />

    would become:

    & lt;label for=”s”& gt;Keyword(s)& lt;/label& gt; & lt;input class=”text” type=”text” value=”” name=”s” id=”s” /& gt;

    (but remove the space between & and l)

    Thread Starter hymerman

    (@hymerman)

    Thanks, I didn’t realise that!

    Since it was going to be a bit tedious I did some googling and found an online tool that will replace characters with HTML entities for you:

    https://www.opinionatedgeek.com/DotNet/Tools/HTMLEncode/Encode.aspx

    Or, you could just wrap in within <code>... </code> tags.

    That won’t work. <code></code> is simply markup. It won’t encode any tags inside.

    Thread Starter hymerman

    (@hymerman)

    Yeah, code tags were the first thing I tried. That would work as long as there weren’t any < or > (or some others) symbols in the code, but since it’s XML they’re quite prevalent ??

    Ah, sorry… I misread the codex page.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How can I make a post that shows HTML code to the reader?’ is closed to new replies.