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. blacksnoopy says:

    Thank you!
    🙂

  2. […] een plugin gevonden voor wordpress waarmee de embedded items van de VRT wél te integreren zijn in wordpress. […]

  3. Michael says:

    Hope you can help.

    I’ve installed the raw html plugin and turned off the visual editor in my profile to be able to have more control over the formatting of my posts. Embedded images show up fine on the home page, but have path problems in the archives and comment pages because of the dynamic directory structure

    I have been hard coding my image paths inside posts

    I can see that’s problematic and have found I should be using something like /images/vd_competitive.gif”

    Since I’m operating inside the raw plugin tags… do I need to escape the bloginfo tag.

    This should be simple. Do the template tags only work in the visual editor context. Help, this simple issue is really frustrating and I’ve found several threads on much the same topic but none anticipate the raw html issue.

  4. White Shadow says:

    …I’m afraid I don’t get it.

    The bloginfo() template tag is a PHP function. Normally, it will not execute when placed inside your posts. You can use a different plugin, like ExecPHP, to make it execute.

    However, if you place it inside the <!–start_raw–><end_raw–> tags, it will not work. This is intentional, and the whole point of the Raw HTML plugin – to prevent WordPress (and other plugins, like ExecPHP) from parsing/changing parts of your posts.

  5. Ben Tremblay says:

    Let the bells ring and the banners fly!

    I’m sure you know you aren’t alone in being frustrated (read: head/desk happens way too often) by WYSIWYG’s behavior. I’ve been having an on-going exchange with Stephen Cronin in his blog and I’ve put together what I hope is a pretty comprehensive resource list at codex.wordpress. My point is: you’re responding to a very real need!

    Would you do one thing for us? Would you, either here with an update or in another post, tell us what the plugin affects or changes to tame the editor?

    TU!
    –bentrem

  6. Ben Tremblay says:

    *sorry, forgot to enable “Notify”*
    bdt

  7. […] to “taming WP WYSIWYG” (thanks to Stephen Cronin for the heads up on this): “Raw HTML Plugin for WordPress” – “To prevent some part of your post or page from being processed and “texturized” […]

  8. White Shadow says:

    The plugin doesn’t “tame” the editor in any way (that’s why I say that using the visual editor is “not recommended” in my post).

    Actually, it only runs when a post is displayed. The plugin intercepts the content surrounded by the special tags and saves it in internal variables before WordPress can “prettify” it. Then, after WP is done messing with the rest of the post, it adds back the “raw” content in the right places.

    So the visual editor is still at large 😉

  9. Ben Tremblay says:

    Wow! “plugin … saves it in internal variables before WordPress can “prettify”. Then … adds back the “raw” content in the right places.” *whooot!* That’s amazing!

    Please don’t take this as diss: goes to show what lengths we’ll go to in order to escape WYSIWYG’s clutches! ;-P

    thanks for this
    cheers

  10. White Shadow says:

    You’re welcome 🙂

  11. Deena Seth says:

    Any way you can integrate htmLawed into this plug-in? Among other things, htmLawed can be used to restrict HTML tags as well as to balance them.

  12. White Shadow says:

    Not integrate, but it looks like an interesting idea for a new plugin. I’ll think about it.

  13. Fernando says:

    Very good!

    Thanks for this

  14. Lee says:

    Thank you really. I have used it in my site and it works well. Keep on!

  15. […] Raw-HTML leaves the HTML you hand-code in an individual post alone. In other words, the WP engine doesn’t b0rk your HTML. […]

  16. […] Raw HTML – Best plug-in ever. Allows you to wrap PHP/HTML/PHP codeblocks in special comments which prevent WordPress from reformatting or encoding them (shocking this is necessary, but a very welcome plug-in) […]

  17. […] Raw HTML. This WordPress plugin could come in handy. […]

  18. Egon says:

    It seems WordPress 2.5 doesn’t like the plugin. Will you be updating it?
    I hope so 🙂

    Thanks

  19. White Shadow says:

    Yes, I plan to eventually update all my plugins for WP 2.5. I’m working on the Single Click Updater plugin at the moment.

Leave a Reply