Last active
December 25, 2015 19:29
-
-
Save tmbritton/7028325 to your computer and use it in GitHub Desktop.
Add classes to <body> tag based on metatag keywords.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_preprocess_html(). | |
* Add classes to <body> tag based on metatag keywords. | |
* | |
* Previous version used hook_node_view() to make keywords accessible to | |
* this function to avoid a node_load(). However, this hook is not available | |
* on mobile due to Panels so this node_load() is necessary to work for | |
* both themes. | |
*/ | |
function hook_preprocess_html(&$vars) { | |
if ($vars['page']['#type'] == 'page') { | |
$node = node_load(arg(1)); | |
$keywordstring = $node->metatags['keywords']['value']; | |
$tags = explode(',', $keywordstring); | |
foreach ($tags as $tag) { | |
$vars['classes_array'][] = drupal_html_class(trim($tag)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment