Raw HTML Plugin for WordPress

Introduction

Recently I needed to put some style definitions and a JavaScript function in a post on another blog that I have. I wasted several hours trying to do this, because WordPress insisted on putting backslashes in front of my apostrophes, inserting superfluous <p> or <br /> tags in place of newlines, and generally breaking my HTML in various horrible ways.

In the end I decided to just go and write a plugin that would let me disable the automatic formatting that WordPress applies to post content. This plugin adds a set of shortcodes that you can use to “protect” specific parts of your post and prevent WP from messing with them.

Download & Installation

Requirements :

  • WordPress 2.8 or later
  • If you use the free version, I strongly recommend disabling the visual editor. It (the editor) can mess up your code even if you use this plugin.

Installation is straightforward – download the zip file, unzip, upload the raw-html folder to /wp-content/plugins and activate it in the Plugins tab.

Usage

There are two ways to use the plugin. First, to turn off “smart quotes” and other built-in filters for an entire post, use the checkboxes that Raw HTML adds to the “Edit Post” screen:

Raw HTML meta box screenshot

If you want to prevent a specific part of your post or page from being processed and “texturized” by WordPress, wrap it in ... or <!–raw–>…<!–/raw–> tags. The two versions work exactly the same, with one exception – the <!–raw–>’s won’t be visible to your visitors even if you deactivate the plugin.

Example :
<!--raw-->
This

is

a ‘test’!
<!–/raw–>

Result :
This is a 'test'!

If you view the source code of this page, you will see that the newlines are still there, and the apostrophes haven’t been converted/escaped.

Other Notes

This plugin is provided AS IS, with no guarantee that it will work on your site.

Related posts :

318 Responses to “Raw HTML Plugin for WordPress”

  1. White Shadow says:

    Right.

    * 4 extra HTML attributes.
    * An extra (per-user?) option in the database for storing the default settings.
    * New UI elements for setting the defaults.
    * Additional code for loading/saving the defaults.
    * Additional code for removing the defaults on uninstall.
    * Additional code for handling edge cases (what about posts created before the new feature was added?).

    ๐Ÿ˜›

  2. Chris says:

    Yeah, I know. I just ment you to hardcode the attributes into the plugin, since I know it’s a lot of work to implement it in the panel. Although you make a point about the edge cases. Too bad ๐Ÿ™

  3. Chris says:

    A temporary solution would be a “remember selection in a cookie” checkbox. How about that? ๐Ÿ˜‰

  4. White Shadow says:

    Argh, fine. I’ve added a “Raw HTML defaults” panel to the “Screen Options” box (and it only took me two days to figure out how to do that :P). You should get an update notification soon.

  5. Chris says:

    Awesome!!! Thanks, m8! ๐Ÿ™‚

  6. BG! says:

    “I’ve added a โ€œRaw HTML defaultsโ€ panel to the โ€œScreen Optionsโ€ box…”

    I’ve just updated and looked for this panel and can’t find it anywhere ๐Ÿ™

    Any ideas?

  7. White Shadow says:

    What’s your WP version? It will only show up in 3.0.

  8. Chris says:

    BG: it shows up when you click “screen options” in the top right corner during new post composition.

    This works fantastic, you just saved like an hour of everybody’s lives ๐Ÿ™‚

    The default settings should also work when I uncheck the RAW HTML box in the screen options, correct?

  9. White Shadow says:

    Mmm, no. But you can collapse the box and put it at the bottom of the page, and the defaults will be applied when you save/update a post.

  10. Chris says:

    Ok, thanks ๐Ÿ™‚

  11. BG! says:

    Got it now, many thanks!

  12. […] Raw HTML capability by Janis Elsts […]

  13. Chris says:

    Just wanted to let you know that the defaults do work even if the raw html box is hidden in the screen options. Testen on a handful of posts ๐Ÿ™‚
    This is great! ๐Ÿ™‚
    You may want to consider adding a explanation on where to find the defaults. The FAQ of WP Plugins repository would be a good place to publish it on ๐Ÿ™‚

  14. jamey says:

    Doesn’t work for me – WP 3.0.

  15. Jason says:

    I’m having a weird issue where this plugin works perfectly for some users, but strips ids for others.

    I’m using WordPress 3.0 with multisite turned on. Users who are Super Admins on the site have no trouble; everyone else is having trouble.

  16. White Shadow says:

    What do you mean by “strips ids”?

  17. Jason says:

    I have a chunk of code:
    [RAW]
    stuff

    When certain users try to use that, it strips out the id=”somename” and just leave the div there. Nothing else is changed.

  18. Jason says:

    The comments keep eating my div tags!

Leave a Reply