3

I am styling a page in a Drupal 7 site that has the title "Weddings & Private Events" and a URL alias of /weddings-private-events but the body class name is weddings-&-private-events which is invalid in CSS See screenshot below: body classes

Is this a bug in D7? I'm using 7.26. Is there a way for me to fix this? I want to style a page specific element without using the node id which may change on export.

7

It's not a D7 bug - all core code uses drupal_html_class(), which removes any dodgy characters (including ampersands) by running the incoming string through drupal_clean_css_identifier().

Presumably your theme (or a custom/contrib module) is adding a class without sanitising it. Look for something like:

function MYTHEME_preprocess_html(&$vars) {
  if ($node = menu_get_object()) {
    $vars['classes_array'][] = str_replace(' ', '-', $node->title);
  }
}

and change it to use

$vars['classes_array'][] = drupal_html_class($node->title);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.