Wordpress is really cool.
But what if you want to have “richer” content? Not just the text you type, but some fancy HTML or PHP stuff? Even if you just want HTML come across exactly as you designed it, the filtering mechanism (wpautop in particular) gets in the way.
So I decided to write a plugin that basically leaves content alone. You just have to add a meta, ‘mime_type’ with value of ‘text/html’ and your post won’t be filtered by wpautop.
I called this plugin Mime because I thought this fits somehow, and also leaves some potential for further enhancement. Well, this plugin is so small I should have called it ‘Basic’ or something like that
The real answer for the name is that I’m using Wordpress in a PHP MVC engine as the CMS, and this engine is really capable of recognizing different mime types and interpreting them at run-time. E.g., you could even implement some Smarty interpretation.
If you have any ideas about some really cool mime stuff for this plugin, please let me know.
Here it is:
<?php
/*
Plugin Name: Mime
Version: 1.0
Plugin URI: http://www.uberdose.com/journal/
Description: Switches wpautop off in cases where the post content is pure HTML.
Author: Dirk Zimmermann
Author URI: http://www.uberdose.com/journal/archives/2004/07/17/mime-wordpress-plugin/
*/
function mime($text) {
global $post_meta_cache, $post;
if (is_array($post_meta_cache[$post->ID]['mime_type'])) {
$mimeType = $post_meta_cache[$post->ID]['mime_type'][0];
}
if (isset($mimeType) && $mimeType == 'text/html') {
return $text;
} else {
return wpautop($text);
}
}
remove_filter('the_content', 'wpautop');
add_filter('the_content', 'mime', 6);
?>
August 5th, 2004 at 4:39 pm
hey I’m going to sound like a tool; but i can’t figure out how to use this!
I have a bunch of html code that i’d like bust out as is … I activated the plugin .. bunged before the html code but .. nothing :’(
August 5th, 2004 at 4:39 pm
hey, i just posted a comment and it’s not showing up!
August 6th, 2004 at 1:56 am
It looks at the meta ‘mime_type’. If this is set to ‘text/html’ it leaves the html alone.
August 16th, 2004 at 9:10 am
I guess I’m a bit confused over this as well. Do you mean that you must add something like
<meta mime_type="text/html" />to each entry you want to disable the formatting on, or if your template already has<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />then it should be fine?For my purposes, I don’t really need a switch, I’d just like to switch wpautop off at all times…thanks for your time and help!
August 19th, 2004 at 1:42 am
I think you’re meant to add a custom field (>advanced editing) with the Key: “mime_type” and the Value “text/html”. These custom fields are called meta data in the Wordpress Wiki (look under Post Meta), but not in Wordpress 1.2 itself.
If that is the case, these meta fields have nothing to do with the meta tags in the html head, actually.
That said, I still couldn’t get it to work. I put < ?php the_meta(); ?> in the code on the index.php page to see if the custom field information actually made it to the entry, and yes, the meta data was included. I checked to see if the plugin was acivated. But the page is still full of
and “
December 1st, 2005 at 10:58 am
hmm…
January 4th, 2006 at 7:03 am
Hm, I’m relying on this plugin for my blog, does it work with WP2.0? I’d rather know about possible difficulties before upgrading
.
May 1st, 2006 at 8:23 am
Yes, Mime works in WP2.
I am having some issues with the Rich Visual Editor (TinyMCE) or its pre/post processing functions mucking with html even if the mime_type => text/html is appropriately set, but it does work nicely for users not using the rich editor. I am currently trying to figure out how to integrate it with the rich editor.
July 21st, 2006 at 12:32 pm
Hello!
I installed Wordpress on my server, and set up a site. It’s a relly nice piece of software. However, I am missing a piece of functionality, and
couldn’t find a suitable answer for it. Mayou you know a plugin I could use?I need to automatically inserts ads in my posts.And not AdSense ads, but rather HTML snippets defined by me (affiliate links, etc). Let’s say I would insert a tag in my post:
– ad here –
and the plugin would automatically replace it with some HTML code, when the post is displayed on my site.I really don’t need any fancy configuration options etc, just the basic replace functionality.
Do you know a plugin that can handle this?
August 8th, 2007 at 6:05 pm
if you use the mighty adsense plugin you can put any affiliate code you want in the box, not just adsense