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

    Hello, long time I don’t come to your site!

    And I came again to ask the same question, what changed on v1.2.4? 😛

  2. White Shadow says:

    A changelog was added 😛 Check the readme.txt, or here. No changes otherwise.

  3. Ant says:

    THANK YOU! THANK YOU! THANK YOU!

    God, it was killing me that when wordpress was stripping/changing my div tags and such.

  4. Hi, when I installed the plugin on one blog it works great, however when installed on another blog I can see my code in the page source!

    Do you know what the problem could be?

  5. White Shadow says:

    What do you mean by “see [your] code in the page source”? What code would that be/why is that bad?

  6. Jeff says:

    for wordpress MU 2.8.4a the only way I could get the autop to not add the p tags to my content was to comment out the call to wpautop in wp_richedit_pre method in wp-includes/formatting.php.

    function wp_richedit_pre($text) {
    // Filtering a blank results in an annoying \n
    if ( empty($text) ) return apply_filters(‘richedit_pre’, ”);

    $output = convert_chars($text);
    // $output = wpautop($output);
    $output = htmlspecialchars($output, ENT_NOQUOTES);

    return apply_filters(‘richedit_pre’, $output);
    }

  7. […] The boys of lightly seasoned were looking for a way to disseminate their events, pictures and videos.  The more I work with CMS built sites (WordPress in this case), the more I buy in to the idea of owner of the site maintaining the content without knowing or writing a lick of code.  The events calendar is fed from a user owned Google Calendar making use of the wpng-calendar plugin.  The pictures live in a user owned Picasa account and makes it way to the page courtesy of the shashin plugin.  To bring the JavaScript to the page, I make use of the Raw HTML plugin. […]

  8. Amazing plugin! ++++
    thank you for a good tool.

  9. Anton Kolin says:

    Well done! Big thanks for you from Russia! This plugin has really help for me.

  10. wsh says:

    Can you make this compatible with the Intypo plugin? Thanks!

  11. White Shadow says:

    Done. The update will be up on wordpress.org in a few minutes.

  12. Mario Stevenson says:

    RAW-HTML I had view a lot of plug-ins to find this one. Hell yea…this was exactly what I was looking for. The reason I needed this plug-in was all the Google Docs plug-ins that I had used…failed! This plug-in is in fact the most successful plug-in to use for embedding Google Docs.

  13. Dan says:

    It worked!!
    I embedded a google form on my wp site!!
    Yay!
    Thank you!

  14. Shaliwahan says:

    Wow that great. Thanks for that pal..

  15. Alberto says:

    It works great on Posts how can I get this to work on Pages?

  16. White Shadow says:

    Normally you don’t need to do anything special to make it work on pages. Can you think of anything unusual about your pages that might be causing the problem? Non-default templates? Some kind of page plugin (whatever that might be)?

  17. Alberto says:

    For whatever reason it Pages mess up my HTML as bad as Post… Huge spaces all kinds of line breaks….

    For now I will forward my pages to a post and use this great tool.

    Unless someone has experienced this crazy problem.

    Thanks WS

  18. Mario Stevenson says:

    I’m sorry, but I can’t see where everyone is having these problems, even in the latest edition of WP. For most of these issues regarding html, a simple html editor can be used first to test the html. When applying the plug-in, I had never experienced any difficulties where the plug-in didn’t work. Is there anything that anyone would like me to try in attempt to localize any further issues?

Leave a Reply