Weblog Tools Collection: ¿Habla HTML?

Find the latest vBulletin information about Weblog Tools Collection: ¿Habla HTML? relating to Wordpress at The Staff Lounge. This was a vBulletin news entry posted 6 months, 2 weeks ago. Weblog Tools Collection: ¿Habla HTML?.




Weblog Tools Collection: ¿Habla HTML?

Wordpress

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

  1. Paste the code above in a file called functions.php inside the theme folder of your currently active theme.
  2. Go into the theme folder of the currently active theme, open the header.php file, 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.
  3. 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, Wordpress

No Responses to “Weblog Tools Collection: ¿Habla HTML?”  

  1. No Comments

Leave a Reply



About This Entry

About This Entry
  • You’re currently reading “Weblog Tools Collection: ¿Habla HTML?,” an entry on The Staff Lounge

  • Published at 9.1.09 / 1pm

Powered By

Living Off

Forums Powered By vBulletin Blog Powered By Wordpress Skin Designed By Binary Bonsai