DISCLAIMER: This post is in no way intended to promote HTML over XHTML or vice-versa. This is simply a solution to a problem for those who may find it useful.
Anyone who has used WordPress for any decent length of time probably knows that everything it outputs is in XHTML format. For those who prefer this, that’s just fine. However, for those of us out there that prefer to use HTML instead, we’re pretty much out of luck when it comes to WordPress. As it stands now, there is no easy way to make WordPress output in HTML format. But today I hope to help those people with this simple function I found around the web.
First, the code:
function HTMLify($buffer) {
$xhtml = array('/XHTML 1.0 Transitional|XHTML 1.0 Strict|XHTML 1.0 Frameset|XHTML 1.1|XHTML Basic 1.0|XHTML Basic 1.1/', '/xhtml1\/DTD\/xhtml1-transitional.dtd|xhtml1\/DTD\/xhtml1-strict.dtd|xhtml11\/DTD\/xhtml11.dtd|xhtml-basic\/xhtml-basic10.dtd|xhtml-basic\/xhtml-basic11.dtd/', '/\/>/', '/\/\s+>/', '/xmlns="http:\/\/www.w3.org\/1999\/xhtml"/', '/\s+xmlns="http:\/\/www.w3.org\/1999\/xhtml"/', '/\s+xml:lang="(.*)"\s+lang="(.*)"/', '/\s+>/');
$html = array('HTML 4.01', 'html4/strict.dtd', '>', '>', '', '', '', '>');
return(preg_replace($xhtml, $html, $buffer));
}
Usage
- Paste the code above in a file called
functions.phpinside the theme folder of your currently active theme. - Go into the theme folder of the currently active theme, open the
header.phpfile, and paste this before any other code that outputs to the browser:
<?php ob_start('HTMLify') ?>
To use the default WordPress theme as an example, paste this code before the DOCTYPE declaration. - Save everything! That’s it! If you now look at the source code for your site you’ll notice that everything is HTML instead of XHTML.
Explanation
Basically, what the code does is, it takes the entire output of the page currently being requested and runs it through our function called HTMLify. The function looks for various XHTML-type code and replaces it with HTML-type code. Pretty simple.
The true beauty of it is the function happens after everything is output by WordPress. So, all of WordPress’s code AND any of your custom code is converted. So you could even continue to code in XHTML but have it output as HTML. Cool huh?
An Alternative
While looking around the web I also came upon this website which has a plugin for WordPress that does the same job. Those of you who prefer to use plugins may be more interested in this approach.
Anyway, that’s all there is to it. A little bit of code to solve a big problem. Enjoy!
Tags: plugin, WordpressSearch
About This Entry
- You’re currently reading “Weblog Tools Collection: ¿Habla HTML?,” an entry on The Staff Lounge
- Published at 9.1.09 / 1pm
Related Entries
- Small Afterdark Skin update - vBStyles
- Alex King: Which DOCTYPE to use for WordPress Themes? - Wordpress
- Weblog Tools Collection: WordPress Theme Releases for 05/02 - Wordpress
- Weblog Tools Collection: How to Highlight Search Terms with jQuery - Wordpress
- Mark Jaquith: TextMate WordPress Widget Snippet - Wordpress
Recent Entries
- Announcements Free Twitter Followers With New Skinz Purchase - ExtremePixelsSite Announcements
- offtopicden community acquired by wetalk.network - NewsvBulletin Fans
- BT – Newest members with [avatar] on forumhome. - vBulletin 3.7 Add-onsvBulletin Add-ons
- Demo forum updated to vBulletin 3.8.5 - AnnouncementsvBStyles
- Customers Support Updates - AnnouncementsvBStyles
Popular Resources
- Phorum-5.2.8 final released (13 replies) - 30167 Views
- Phorum-5.2.9a released (10 replies) - 26869 Views
- IPB Resources - 11194 Views
- Weblog Tools Collection: WordPress Theme Releases for 01/14 - 9394 Views
- Weblog Tools Collection: WordPress Plugin Releases for 02/07 - 8816 Views







No Responses to “Weblog Tools Collection: ¿Habla HTML?”
Please Wait
Leave a Reply