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 :
November 11th, 2008 at 10:23 pm
@Aardvark - Yes, it hasn’t been extensively tested with the visual editor.
November 8th, 2008 at 10:27 pm
This plugin is a lifesaver. Simple and effective. Just a note, it’s not compatible with the tinymce-advanced plugin. Thanks a million!
November 2nd, 2008 at 6:53 pm
[...] Raw HTML позволяет вставлять при написании / редактировании [...]
September 26th, 2008 at 9:02 pm
This is -JUST- what i was looking for. Thank you so much!
September 9th, 2008 at 2:39 am
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.
August 4th, 2008 at 11:16 pm
@Esteban - Ah well, good luck
August 4th, 2008 at 11:06 pm
@White Shadow - PS, the last post was in FF3 and worked this time. lol. I love the consistency of inconsistency.
August 4th, 2008 at 11:05 pm
@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.
August 4th, 2008 at 8:51 pm
@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.
August 4th, 2008 at 8:43 pm
@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.)
August 4th, 2008 at 8:41 pm
(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)
August 4th, 2008 at 11:24 am
@Esteban - This plugin was never intended for executing PHP. You will need a different plugin like Exec-PHP for that.
August 4th, 2008 at 7:44 am
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
August 2nd, 2008 at 12:22 am
@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.
July 30th, 2008 at 10:13 am
Love this plugin. Would love to see 2.5 compatibility.
July 29th, 2008 at 12:38 am
Thanks…..
July 28th, 2008 at 1:10 pm
This is a nice plugin
July 27th, 2008 at 3:55 am
Good plugin.
July 26th, 2008 at 3:54 am
Great Blog…Looking to captilize from blogging as well.
July 10th, 2008 at 4:31 am
[...] 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 [...]
July 8th, 2008 at 4:48 pm
Thanks a lot
July 7th, 2008 at 10:26 pm
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.
June 30th, 2008 at 1:18 am
שיש,שישלמטבח,שיש למטבחים
June 27th, 2008 at 12:22 pm
thanks for the raw html =)
June 22nd, 2008 at 7:10 pm
@Hikari - Just a small bugfix in 1.0.4, no changes in functionality.
June 22nd, 2008 at 4:28 pm
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?
June 18th, 2008 at 9:13 pm
Ah, so it’s in Google News? Interesting…
(or is the comment just very clever spam? in that case, congratulations, it works well
)
June 18th, 2008 at 8:16 am
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..
June 14th, 2008 at 11:47 am
wow..nice plugin thanks
Cheers,
Online Issues
May 16th, 2008 at 1:58 pm
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