How to add xmlns attribute for Facebook in Adaptivetheme
This is a "how to" article which describes how to add the Facebook xmlns:fb
attribute to the html element.
Normally you would probably hard code something like this in html.tpl.php
, however in Adaptivetheme we can push this into a variable in preprocess, thus removing the requirement for a template override and making this a two second copy'n'paste sort of thing.
This is particularly useful since AT uses the same IE classes trick as HTML5 Boilerplate, so you would need to hard code the xmlns:fb
attribute a number of times and it can be kind of confusing where to stick the code - using preprocess and the variable makes this trivial.
In themename_preprocess_html()
you can add to the $html_attributes
variable, which is flattened in process using drupal_attributes()
and printed in html.tpl.php
- by default this variable holds the language and lang dir.
Therefor its dead easy to push something else into the array, e.g. for Facebook widgets we normally need to add an xmlns:fb
attribute, so in preprocess we can do just that:
<span style="color: #000000"><span style="color: #0000BB"><?php<br></span><span style="color: #007700">function </span><span style="color: #0000BB">themename_preprocess_html</span><span style="color: #007700">(&</span><span style="color: #0000BB">$vars</span><span style="color: #007700">) {<br> </span><span style="color: #FF8000">// Add facebook xlms attribute to the html element, required by IE<br> </span><span style="color: #0000BB">$vars</span><span style="color: #007700">[</span><span style="color: #DD0000">'html_attributes_array'</span><span style="color: #007700">][</span><span style="color: #DD0000">'xmlns:fb'</span><span style="color: #007700">][] = </span><span style="color: #DD0000">'http://www.facebook.com/2008/fbml'</span><span style="color: #007700">;<br>}<br></span><span style="color: #0000BB">?></span></span>
Clear the cache and bobs your uncle.