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 :
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.
@White Shadow:
That sounds great. Quick respons. I look forward to reading more tomorrow then.
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?
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?
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.
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.
Thank you for the share, this is going to be really useful for my WordPress website 🙂
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.
Hmm, that probably wouldn’t work.
I installed your plugin, but WordPress still eats my tags. Help!
Could you post an example?
(If the comment form eats your code use the Contact page instead.)
[…] 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. […]
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?
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:
That is fine, but what do you do for a raw html block that begins the post?
That block gets wrapped in a paragraph no matter what. Is the only solution disabling autop?
I wonder if this would work:
Unfortunately that doesn’t make a difference. WP wraps the raw html block and the normal text into one paragraph.
Bummer.
[…] is one very useful plugin Raw HTML. This plugins allows you to include HTML content in […]
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/
[…] 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/) […]