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:
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 :
Thank you!
🙂
[…] een plugin gevonden voor wordpress waarmee de embedded items van de VRT wél te integreren zijn in wordpress. […]
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.
…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.
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
*sorry, forgot to enable “Notify”*
bdt
[…] 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” […]
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 😉
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
You’re welcome 🙂
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.
Not integrate, but it looks like an interesting idea for a new plugin. I’ll think about it.
Very good!
Thanks for this
Thank you really. I have used it in my site and it works well. Keep on!
[…] Raw-HTML leaves the HTML you hand-code in an individual post alone. In other words, the WP engine doesn’t b0rk your HTML. […]
thnak you 😀
[…] 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) […]
[…] Raw HTML. This WordPress plugin could come in handy. […]
It seems WordPress 2.5 doesn’t like the plugin. Will you be updating it?
I hope so 🙂
Thanks
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.