Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Facebook like button HTML validation

Tags:

html

facebook

After adding the new facebook like button on my page, it's no longer validates using XHTML strict standard. The two errors I come across are:

  1. All of the meta property tags say that there is no attribute property;
  2. All of the variables used in the like button line are listed that there are no attributes for it. The line is as follows:

    <fb:like href="http://www.pampamanta.org" layout="button_count" show_faces="false" width="120" action="like" font="arial" colorscheme="light"></fb:like>

like image 442
Eric Di Bari Avatar asked May 03 '10 22:05

Eric Di Bari


People also ask

How do I add a like button to my facebook page 2021?

Go to your Page. Tap Add a Button. Tap to choose an action and follow the on-screen instructions. Tap Save.

How do you code like buttons?

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> </head>


2 Answers

starting today you can also use HTML5-compliant markup

e.g. instead of

<fb:like href="example.org"> 

you can do

<div class="fb-like" data-href="example.org"> 

Since data-* attributes are valid in HTML5

like image 33
Stoyan Avatar answered Sep 18 '22 03:09

Stoyan


Here is a solution for not swapping doctype:

As zerkms suggested, adding the "fb" namespace only applies for the "fb:" attributes. The "property" attribute of the meta tag remains invalid XHTML.

As you know, Facebook builds upon the RDFa compliance, so you could use the following doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">  

Using RDFa brings more problems than the simple FB issue fix in most cases though.

as _timm suggested, dynamically writing the meta tags to the dom doesn't make any sense. One of the major uses of these fb meta tags is the FB-bot parsing of a "share" or "i like" target page (action page) to provide custom titles, images and anchor label for the facebok wall post auto population. Given that fact and given the fact that facebook most certainly uses a simple page fetch to read in the delivered html response without any capability of parsing a related meta tag inject by javascript, the intended functionality will simply fail.

Now, there is a pretty simple fix to provide a compromise between a XHTML validation and successful parsing by facebook : wrap the facebook meta in html comments. That bypasses the w3c parser and facebook still recognizes the meta tags, cause it ignores the comment.

<!-- <meta property="og:image" content="myimage.jpg" /> <meta property="og:title" content="my custom title for facebook" /> --> 
like image 101
XtraBytesLab Avatar answered Sep 20 '22 03:09

XtraBytesLab