Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 7 down vote accepted

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);
share|improve this answer
+1 for the example. I have seen similar in many commercial themes. – AyeshK Jun 10 '14 at 13:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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