Forums

How can I make a post that shows HTML code to the reader? (7 posts)

  1. hymerman
    Member
    Posted 2 years ago #

    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!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    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)

  3. hymerman
    Member
    Posted 2 years ago #

    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:

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

  4. ousep
    Member
    Posted 2 years ago #

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

  5. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  6. hymerman
    Member
    Posted 2 years ago #

    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 :)

  7. ousep
    Member
    Posted 2 years ago #

    Ah, sorry... I misread the codex page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.