Instantly share code, notes, and snippets.

What would you like to do?
Drupal 7 - Add transformed page title as a body class.
* 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) {}

This comment has been minimized.


davidcraig commented Jul 19, 2017

replace MYTHEME with the machine(folder) name of your theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment