Skip to content

Instantly share code, notes, and snippets.

@davidcraig davidcraig/template.php
Last active Jul 19, 2017

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.

Copy link
Owner Author

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
You can’t perform that action at this time.