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:

function themename_preprocess_html(&$vars) {
// Add facebook xlms attribute to the html element, required by IE
$vars['html_attributes_array']['xmlns:fb'][] = '';

Clear the cache and bobs your uncle.

Last updated 14th March, 2013 - 10:19pm

Authored by Jeff Burnz on