How to Include Code in WordPress Posts

If you’ve ever tried to insert code into a WordPress post, one of the following has probably happened to you:

  • Your HTML code was rendered as such.
  • WordPress stripped the code from the post entirely.
  • WordPress turned "straight quotes" into “curly quotes” — not good if you want your users copying/pasting code from your blog!

Here’s how to get around these annoying problem and make the code show as-is:

  1. Put the code into a basic text processing program (like Notepad), and perform the following find/replace operations:

    Find Replace
    < &lt;
    > &gt;
    " &quot;
  2. Click the “Code” tab on the WordPress post composition page, and then paste in the “fixed” code.

  3. Be sure to encase your code in a <code> tag for purposes of semantic correctness.

Check out the Writing Code in Your Posts WordPress Codex article for more lengthy take on the issue.

Did you enjoy this post? to get even more WordPress tips, news, and resources!

StumbleUpon

One Comment

  1. Adriana
    Posted January 21, 2010 at 11:59 am | Permalink

    Excelent tutorial! This is better than installing a plugin. Thanks!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*