Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 6 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  
+1 for the example. I have seen similar in many commercial themes. –  Ayesh K Jun 10 at 13:35
add comment

Your Answer

 
discard

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.