Facebook meta tag validation for HTML5
Facebook meta tag validation for HTML5

February 07 2012

I've recently ran into an interesting problem : V3C Validator shows errors checking facebook meta tags for HTML5 doctype. Official facebook forum has no solution for this problem at the moment.

However there is one. See the PHP code below, code goes without explanation.

<?php
function is_facebook(){
    if(!(stristr($_SERVER["HTTP_USER_AGENT"],'facebook') === FALSE))
        return true;
}
?>
<!DOCTYPE html>
<html <?php if(is_facebook()){
echo 'xmlns:fb="http://www.facebook.com/2008/fbml" 
xmlns:og="http://opengraphprotocol.org/schema/"';}?>>
<head>
<title>This Maybe It</title>
<meta http-equiv=”Content-Typecontent=”text/html; charset=UTF-8″ />
 
<?php if(is_facebook()){?>
<meta property="og:title" content="<?php echo $mytitle;?>"/>
<meta property="og:description" content="<?php echo $mydescription;?>"/>
<meta property="og:type" content="website"/>
<meta property="og:image" content="http://mysite.com/images/myimage.jpg"/>
<meta property="og:url" content="http://mysite.com"/>
<meta property="og:site_name" content="My Site"/>
<meta property="fb:appid" content="<?php $my_app_id ?>"/>
<?php }?>

Comments

August 16, 2012 05:07
Arkadiusz

This script dosnt work correctly Check this is

Line 5, Column 69: Internal encoding declaration named an unsupported chararacter encoding utf-8″.

Line 5, Column 69: Bad value ”Content-Type” for attribute http-equiv on element meta.

Line 5, Column 69: Attribute charset not allowed on element meta at this point.

August 17, 2012 07:05
monkey

I think the script works, it's the quotes that doesn't. Try retyping them manually.

You can check this website : http://idol-studio.md, if you open it's source codes - you'll see this exact line of code

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

and it's error free.

Current site cost is : 470.5$
In conversion to other values our site costs :
   - 353.8 euro
   - 4.9 oil barrels
   - 0.3 gold troy ounce
   - 0.3 platinum
idolit twitteridol-it
  • http://t.co/S74dfgi4 http://t.co/7OujRur8December 25, 2012
  • Idol-Interactive has been featured at Flash Awards' website! http://t.co/WlCuu8z1 http://t.co/japM1GSwDecember 1, 2012
  • http://t.co/dXd0hgym http://t.co/LaJWEQgdNovember 30, 2012