Last active
July 19, 2017 08:53
-
-
Save davidcraig/73c8245880fad79b89666bd3fdd17033 to your computer and use it in GitHub Desktop.
Drupal 7 - Add transformed page title as a body class.
This file contains 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
<?php | |
/** | |
* HTML template preprocessing. | |
*/ | |
function MYTHEME_preprocess_html(&$variables) { | |
// Add the page title as a css class to allow for page specific targetting. | |
try { | |
if (!drupal_is_front_page()) { | |
$title = drupal_get_title(); | |
$titleClass = trim(strtolower(str_replace(' ', '-', $title))); | |
$variables['classes_array'][] = $titleClass; | |
} | |
} catch (Exception $e) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replace MYTHEME with the machine(folder) name of your theme.