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 put any code or script (e.g. JavaScript) in my posts and display it to the visitor unmodified.

Requirements & Download

I have only tested it in WordPress 2.3.1 - 2.6, but I’m fairly certain the plugin will work in older WP 2.x versions, too. I recommend disabling the visual editor for better results - if it’s enabled enabled, some characters (e.g. the ampersand) may still be encoded.

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

Download raw-html.zip (2 KB)

Using the plugin

To prevent some part of your post or page from being processed and “texturized” by WordPress, wrap it in <!–start_raw–>…<!–end_raw–> or [RAW]…[/RAW] tags. The two versions work exactly the same, but the latter may be handy if you’re using the visual editor (not recommended).

Example :
<!--start_raw-->
This

is

a 'test'!
<!--end_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. If it works for you, consider yourself lucky ;)

You might also be interested in another functionally similar plugin - WP Unformatted - that works on per-post basis.

Related posts :

68 Responses to “Raw HTML Plugin for WordPress”

  1. 1
    blacksnoopy Says:

    Thank you!
    :)

  2. 2
    De redactie .be Says:

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

  3. 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. 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. 5
    WordPress Plugin — Raw HTML | AVINASH 2.0 Says:

    [...] Raw HTML is a WordPress plugin that allows you to put any code or script in your posts and display it to the visitor unmodified. [...]

  6. 6
    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

  7. 7
    Ben Tremblay Says:

    *sorry, forgot to enable “Notify”*
    bdt

  8. 8
    Buffer Dump 17JAN08 « Feet up, eyes closed, head back Says:

    [...] 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” [...]

  9. 9
    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 ;)

  10. 10
    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

  11. 11
    White Shadow Says:

    You’re welcome :)

  12. 12
    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.

  13. 13
    White Shadow Says:

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

  14. 14
    Raw HTML_Wordpress plugin Says:

    [...] Plugin Homepage [...]

  15. 15
    Fernando Says:

    Very good!

    Thanks for this

  16. 16
    Lee Says:

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

  17. 17
    WordPress Plugins Database » Blog Archive » Raw HTML capability Says:

    [...] Visit [...]

  18. 18
    Wp Wordpress » Blog Archive » Raw HTML capability Says:

    [...] Visit [...]

  19. 19
    Big IDEA » Blog Archive » Three helpful Wordpress plugins for web geeks Says:

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

  20. 20
    The Plugin | Daniel Daphone Says:

    [...]   Raw HTML capability 1.0.2 » Janis Elsts (url) Lets you enter raw HTML in your posts. See website for details. [...]

  21. 21
    absolut-desing Says:

    thnak you :D

  22. 22
    Wp Wordpress » Blog Archive » Raw HTML Says:

    [...] Plugin Homepage ; [...]

  23. 23
    Mike Davidson - Mike Industries Now Powered By WordPress Says:

    [...] 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) [...]

  24. 24
    Raw HTML | Futurosity Grapevine Says:

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

  25. 25
    Egon Says:

    It seems Wordpress 2.5 doesn’t like the plugin. Will you be updating it?
    I hope so :-)

    Thanks

  26. 26
    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.

  27. 27
    Alec Says:

    Thanks for the plugin.

    We took a different approach to the vagaries of the Wordpress visual editor - which does terrible things to code of all times. Instead of fighting a losing war with the built-in WYSIWYG editor, we wrote a hardcore adaptation of FCK including an integrated image uploader-manager specifically for Wordpress.

    We still do have some issues with trying to place straight code (particularly html code) within a post. After flipping back and forth between WYSIWYG and source, the angled brackets turn to html entities, like it or not. We’ll try to adapt your code to Foliopress WYSIWYG.

  28. 28
    White Shadow Says:

    Looks like the WP 2.5 editor is a bit more flexible in this regard, though obviously not perfect. Anyway, good luck :)

  29. 29
    Tony Cabrera Says:

    Love this plugin. Would love to see 2.5 compatibility. Would also be interested in donation when it’s done.

    Thanks

  30. 30
    White Shadow Says:

    You’re welcome :)
    By the way, have you tried using the current version in WP 2.5? I haven’t done in-depth testing, but it seems to work OK on my blogs that are running WordPress 2.5.

    Guess I’ll have to finally put up a “Donate” button on the site.

  31. 31
    Tony Cabrera Says:

    Not yet, I’ll try it on a separate blog first. I’ve put too much work on my current one to screw it up.

    Yes, I’d be happy to donate. Your plugin is exactly what I needed.

  32. 32
    Tony Cabrera Says:

    Test site looks good, I’ll convert to 2.5 sometime this weekend. Donation on its way, thanks again for the plugin!

  33. 33
    White Shadow Says:

    Thank you :)

  34. 34
    Michael Says:

    this is a critical plugin for my site, since all my posts use it, I’m terrified of upgrading to 2.5 and having things fall apart.

    From the last comments in this thread, it sounds like you think it should work, have you come across any issues since you made that comment a couple of weeks ago.

    I might take a crack at the 2.5 upgrade this weekend.

  35. 35
    White Shadow Says:

    I’ve updated to 2.5.1 recently and the plugin seems to be working still.

  36. 36
    Tony Cabrera Says:

    Michael,

    Same as you, all my post (112 of them) includes this plugin. I’ve converted to 2.5.1 and no problems at all. In fact it looks like 2.5 is a little more html-friendly. But I still require this plugin to work my blog.

    I did create a test blog (seprate site) and tested it first before I converted. You should probably create a test blog too just to be safe.

  37. 37
    HTML Guru Says:

    So, if im trying to add in a youtube video will WP still reformat the objects?

  38. 38
    White Shadow Says:

    I don’t know, I haven’t tried adding the videos directly (I used a plugin when I needed to insert a video). It would also depend on the WP version - 2.5 is said to be more forgiving in this regard.

  39. 39
    Voddie Says:

    Ive just come across your plugin, I’m using WP 2.5.1, because I need to add a few tables within my pages.

    I did as instructed, unzipped, uploaded, activated and tried a simple table inclusion.

    I used the ….. syntax and it worked a dream.

    Brilliant plugin, thanks very much

    Voddie

  40. 40
    Mat Says:

    wow..nice plugin thanks
    Cheers,
    Online Issues

  41. 41
    watch-street-fights Says:

    Hi all great information here and good thread to comment on.

    Can I ask though - how did you get this picked up and into google news?

    Very impressive that this blog is syndicated through Google and is it something that is just up to Google or you actively created?

    Obviously this is a popular blog with great data so well done on your seo success..

  42. 42
    White Shadow Says:

    Ah, so it’s in Google News? Interesting…

    (or is the comment just very clever spam? in that case, congratulations, it works well ;) )

  43. 43
    Hikari Says:

    Tnx a lot for this plugin dude, it’s the best plugin I use on my blog!

    btw, what’s the changes on 1.0.4?

  44. 44
    White Shadow Says:

    @Hikari - Just a small bugfix in 1.0.4, no changes in functionality.

  45. 45
    Movie Goers Says:

    thanks for the raw html =)

  46. 46
    שיש Says:

    שיש,שישלמטבח,שיש למטבחים

  47. 47
    teko Says:

    Hi,

    I’m having some problems with this plugin. Posted a feedback here: http://wordpress.org/support/topic/187334?replies=1#post-798122

    Using 1.0.4, also tested in new wordpress 2.5.1 installation with no other plugins.

  48. 48
    y5cafe Says:

    Thanks a lot :)

  49. 49
    Indi in the Wired » Equations Enabled, for Better or Worse Says:

    [...] solution was simple with the help of yet another plugin. This time, I turned to Raw HTML from W-Shadow (see also the WordPress Official Plugins Directory page for Raw HTML. That plugin [...]

  50. 50
    Ebony Says:

    Great Blog…Looking to captilize from blogging as well.

  51. 51
    Photographion Says:

    Good plugin.

  52. 52
    Philix Says:

    This is a nice plugin

  53. 53
    FMS GROUP Says:

    Thanks…..

  54. 54
    gazete oku Says:

    Love this plugin. Would love to see 2.5 compatibility.

  55. 55
    White Shadow Says:

    @gazete oku - I think it’s compatible, though I haven’t tested it extensively. This blog uses WP 2.6 and the example in the post seems to work correctly.

  56. 56
    Esteban Says:

    I am not sure if it was the recent WP update or what, but this plug-in doesn’t seem to allow for php to be executed. If you view source, it simply prints the php source code. None of it is parsed. :/

    Any advice?

    - Esteban

  57. 57
    White Shadow Says:

    @Esteban - This plugin was never intended for executing PHP. You will need a different plugin like Exec-PHP for that.

  58. 58
    Esteban Says:

    (testing possible commenting problem…) (this post can be deleted if it works) (sure wish i had comment previewing…) (btw, the problem was with FF3 and I am trying this on IE 6 now)

  59. 59
    Esteban Says:

    @White Shadow - Oh. I didn’t realize that. When I read the description, it said “In the end I decided to just go and write a plugin that would let me put any code or script in my posts and display it to the visitor unmodified.”

    I thought any code included php. Did you mean only Java script and html?

    As for Exec-PHP, I do use it. however, unless you enclose the whole post in the php brackets, Wordpress will add parsing. That is why I was excited about your plug in. Here is an example (curlies instead of brackets):

    CODE with Exec-PHP:
    ——————
    line 0: {?php echo “stuff”; ?}
    line 1:
    line 2: {h1}title{/h1}
    line 3:
    line 4: {?php echo “more stuff”; ?}

    WP output with Exec-PHP:
    ——————
    stuff

    TITLE

    more stuff
    ——————

    As you can see, there are line breaks added because WP is annoying. lol.

    Now, with your plugin, what I had hoped to do because I thought in included php code was the following:

    CODE with Exec-PHP and Raw HTML:
    ——————
    line 0: {!–start_raw–}
    line 1: {?php echo “stuff”; ?}
    line 2:
    line 3: {h1}title{/h1}
    line 4:
    line 5: {?php echo “more stuff”; ?}
    line 6: {!–end_raw–}
    ——————

    Desired WP output with Exec-PHP and Raw HTML:
    ——————
    stuff
    TITLE
    more stuff
    ——————

    Anyway, that is what I expected since you said that we code execute ANY code or script. :/

    It’s okay if you don’t want to include this ability. I don’t want to tell you how to right your code and I CAN echo all the html with php (which would be annoying, but possible).

    I do hope you can update this post though to better reflect what “any code or script” means.

    Thanks for all your work my friend!

    Esteban

    (Ps - I don’t know what was up with your WP-SpamFree plugin, but I wasn’t able to post this with FireFox3.)

  60. 60
    White Shadow Says:

    @Esteban - Yes, it was for JS/HTML. And your example might work if you did it like this :

    line 1: {?php echo “stuff”; ?}{!–start_raw–}
    line 2:
    line 3: {h1}title{/h1}
    line 4:
    line 5: {!–end_raw–}{?php echo “more stuff”; ?}

    Though that would likely become tedious in practical situations.

    WP-SpamFree might cause problems if you have JS and/or cookies disabled, but there may be other possibilities that I’m not aware of.

  61. 61
    Esteban Says:

    @White Shadow - Thanks for the type. Unfortunately, I have tried that as well. I basically used the {!–start/end_raw–} tags to kill WordPress auto-formatting. You simply can’t use RAW HTML with Exec-PHP.

    Echoing line by line or even in EXCERPTS can be handy, but when you want to print variables within it, that it turns out to be a problem. :-/

    Anyway, thanks for the replies. Also, thanks for plugging the Javascript addition in there. I think it will clear thing up for folks. Now it’s time for me to either find another plug-in or write one myself (which will suck because I know in two weeks I will find out that I just reinvented the wheel and someone else already did it. lol)

    As for the WP-SpamFree, it warned me of the exact problems you suggested both of which were not the case. All well. That’s why I use multiple browsers.

  62. 62
    Esteban Says:

    @White Shadow - PS, the last post was in FF3 and worked this time. lol. I love the consistency of inconsistency.

  63. 63
    White Shadow Says:

    @Esteban - Ah well, good luck ;)

  64. 64
    Alan Tucker Says:

    Great, works on a 2.6.1 (test, different theme) blog I’m considering migrating to - from 2.3.3 - it allowed me to put html tables into a page, I was pulling what’s left of my hair out before !

    Many thanks, Alan.

  65. 65
    Czar Says:

    This is -JUST- what i was looking for. Thank you so much!

  66. 66
    Как вставить кусок html кода, или таблицу стилей в Ваш пост » Плагины » Темы и Плагины для Wordpress Says:

    [...] Raw HTML позволяет вставлять при написании / редактировании [...]

  67. 67
    Aardvark Says:

    This plugin is a lifesaver. Simple and effective. Just a note, it’s not compatible with the tinymce-advanced plugin. Thanks a million!

  68. 68
    White Shadow Says:

    @Aardvark - Yes, it hasn’t been extensively tested with the visual editor.

Leave a Reply