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:

    Just a small note: I have read the above comments, but I don’t have an immediate fix in mind and it’s already 1:00 AM here. So I shall look into this tomorrow, at the earliest.

  2. Ryanowich says:

    @White Shadow:
    That sounds great. Quick respons. I look forward to reading more tomorrow then.

  3. White Shadow says:

    Okay, I think I know why the script is printed like that on your site.

    What should the plugin do instead, though? Strip the code block(s) completely?

  4. Ryanowich says:

    I would be a perfectly working solution to strip the code block completely. And I would definitely use that.

    I haven’t yet changed my template to show the first image as a thumbnail for post on a catagory page and on any other page showing excerpts. But I plan to do that.

    In that case I would try to have the first image within the code block be used as the thumbnail picture. Is that possible if your update the plugin to strip out the everything within the code block?

  5. White Shadow says:

    All right, I’ve modified it to strip out code blocks when displaying an excerpt. The modified version will be available at this URL in about 30 minutes (or however long it takes WordPress.org to update the version archive).

    Whether thumbnails work or not will depend on how your template detects them. If it scans the post content – e.g. as returned by get_the_content – or directly analyses the $post object, everything should work just fine. If it tries to find the image in the excerpt, it probably won’t.

  6. Ryanowich says:

    It works perfectly. And does not cause problems with thumbnails. I’ve a modified version of “Get the image”: http://wordpress.org/extend/plugins/get-the-image/

    I chose it because it can show thumbnails from external images too. I modified it to show images from Picasa in a smaller version than what it inserted in the post.

    Thanks a lot.

  7. jeux says:

    Thank you for the share, this is going to be really useful for my WordPress website 🙂

  8. josoroma says:

    Hi Shadow!

    Amazing piece of art. I was trying to know if exist the possibility to let your plugin use:
    http://wordpress.org/extend/plugins/wp-include-file/
    it is like recognize nested shorcuts.

    [RAW]


    [include file=”test.php”]

    [/RAW]

    Thanks in advance.

  9. White Shadow says:

    Hmm, that probably wouldn’t work.

  10. Michael Franzl says:

    I installed your plugin, but WordPress still eats my tags. Help!

  11. White Shadow says:

    Could you post an example?

    (If the comment form eats your code use the Contact page instead.)

  12. […] Raw HTML Plugin for WordPress Raw HTML Plugin for WordPress doesn’t let WordPress to put backslashes in front of apostrophes, insert superfluous tags in place of newlines, and break HTML in various ways. This plugin lets you put any code or script (e.g. JavaScript) in your posts and display it to the visitor unmodified. […]

  13. Aaron Padoshek says:

    This plugin is great and I can’t imagine WordPress without!

    That being said, I noticed that whenever I use the tags without disabling autop, WordPress wraps the entire raw html block in a paragraph. Normally I disable autop, but I have some pages where I would like utilize autop with some raw html blocks.

    Any idea why this is happening? Any chance of a fix?

  14. White Shadow says:

    This is just the way WP works. If you start the raw-html block on a new line, WordPress will treat it as an empty paragraph.

    You can circumvent the problem by not inserting a newline before the <!–start_raw–> tag. For example:

    Normal text or code here.
    [Any HTML here]
    
    More normal text or code.
    
  15. Aaron Padoshek says:

    That is fine, but what do you do for a raw html block that begins the post?

    [HTML]
    More normal text or code.
    

    That block gets wrapped in a paragraph no matter what. Is the only solution disabling autop?

  16. White Shadow says:

    I wonder if this would work:

    [HTML]More normal text or code.
    
  17. Aaron Padoshek says:

    Unfortunately that doesn’t make a difference. WP wraps the raw html block and the normal text into one paragraph.

    Bummer.

  18. […] is one very useful plugin Raw HTML. This plugins allows you to include HTML content in […]

  19. Raw HTML is great plugin. I had strange issue with embed videos. They were not working in some WordPress instances with enabled Raw HTML. I fixed it by changing priority in raw_html.php:139 ‘add_filter( $tag, ‘maybe_’.$func, 3 );’ to 8.

    Here are some further details: http://georgik.sinusgear.com/2011/01/01/wordpress-raw-html-and-problem-with-videos/

  20. […] If you’re decent at PHP you can create a source PHP file with how you want all of your Landing Pages to look, and then use the PHP INCLUDE command on all of your Landing Pages. (Here is a link to a plugin that allows you to put Raw Code into your Post: http://w-shadow.com/blog/2007/12/13/raw-html-in-wordpress/) […]

Leave a Reply