Content Management and MIME Types

Okay, welcome back.

<?php

if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
   header("Content-Type: application/xhtml+xml");
   $con_type = "application/xhtml+xml";
   printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
   printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
   \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
}
else {
   header("Content-Type: text/html");
   $con_type = "text/html";
   printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
   \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
}
?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<title><?php bloginfo('name'); ?> <?php if ( is_single() )
{ ?> » Blog Archive <?php } ?> <?php wp_title(); ?></title>

<meta http-equiv="Content-Type" content="<?php echo $con_type; ?>;
charset=<?php bloginfo('charset'); ?>" />

I know that’s a bit to choke down at once, so, I’ll break it down.

<?php

if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
   header("Content-Type: application/xhtml+xml");
   $con_type = "application/xhtml+xml";
   printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
   printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
   \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
}
else {
   header("Content-Type: text/html");
   $con_type = "text/html";
   printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
   \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
}
?>

This, this is the meat of what we are doing. the first part of the code, the if conditional, checks to see if the browser sends the header announcing that it supports application/xhtml+xml, and, if it does, sends the appropriate PHP header, this is sent before page data, so technically overrides an appropriate meta tag within the document. I repeat it in the document for complete-ness sake. the $con_type variable will be used later, in the meta tag. The 2 printf lines send the encoding, xml version, and doctype to the browser.

The else section of the code is the fallback portion, doing the same things as the if part, but only to browsers that do not support the application/xhtml+xml format.

<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<title><?php bloginfo('name'); ?> <?php if ( is_single() )
{ ?> » Blog Archive <?php } ?> <?php wp_title(); ?></title>

<meta http-equiv="Content-Type" content="<?php echo $con_type; ?>;
charset=<?php bloginfo('charset'); ?>" />

Now, this bit is very similar to what comes with the standard package, and those of you not using a kubrick-based theme may need to alter this, but, here we go.

The major thing is using $con_type in the content="". This really isn’t all that advanced, so I will not get to deep into the discussion.

See page 3 for WHY you should do this.

Pages: 1 2 3

Leave a Reply