Skip to content

Instantly share code, notes, and snippets.

@davidcraig
Last active July 19, 2017 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcraig/73c8245880fad79b89666bd3fdd17033 to your computer and use it in GitHub Desktop.
Save davidcraig/73c8245880fad79b89666bd3fdd17033 to your computer and use it in GitHub Desktop.
Drupal 7 - Add transformed page title as a body class.
<?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) {}
}
@davidcraig
Copy link
Author

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