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 :
Right.
* 4 extra HTML attributes.
* An extra (per-user?) option in the database for storing the default settings.
* New UI elements for setting the defaults.
* Additional code for loading/saving the defaults.
* Additional code for removing the defaults on uninstall.
* Additional code for handling edge cases (what about posts created before the new feature was added?).
๐
Yeah, I know. I just ment you to hardcode the attributes into the plugin, since I know it’s a lot of work to implement it in the panel. Although you make a point about the edge cases. Too bad ๐
A temporary solution would be a “remember selection in a cookie” checkbox. How about that? ๐
Argh, fine. I’ve added a “Raw HTML defaults” panel to the “Screen Options” box (and it only took me two days to figure out how to do that :P). You should get an update notification soon.
Awesome!!! Thanks, m8! ๐
“I’ve added a โRaw HTML defaultsโ panel to the โScreen Optionsโ box…”
I’ve just updated and looked for this panel and can’t find it anywhere ๐
Any ideas?
What’s your WP version? It will only show up in 3.0.
BG: it shows up when you click “screen options” in the top right corner during new post composition.
This works fantastic, you just saved like an hour of everybody’s lives ๐
The default settings should also work when I uncheck the RAW HTML box in the screen options, correct?
Mmm, no. But you can collapse the box and put it at the bottom of the page, and the defaults will be applied when you save/update a post.
Ok, thanks ๐
Got it now, many thanks!
[…] Raw HTML capability by Janis Elsts […]
Just wanted to let you know that the defaults do work even if the raw html box is hidden in the screen options. Testen on a handful of posts ๐
This is great! ๐
You may want to consider adding a explanation on where to find the defaults. The FAQ of WP Plugins repository would be a good place to publish it on ๐
Right.
Doesn’t work for me – WP 3.0.
jamey try this: http://catb.org/esr/faqs/smart-questions.html
I’m having a weird issue where this plugin works perfectly for some users, but strips ids for others.
I’m using WordPress 3.0 with multisite turned on. Users who are Super Admins on the site have no trouble; everyone else is having trouble.
What do you mean by “strips ids”?
I have a chunk of code:
[RAW]
stuff
When certain users try to use that, it strips out the id=”somename” and just leave the div there. Nothing else is changed.
The comments keep eating my div tags!