I'm trying to get either the title of a page or the menu entry to be listed as a class in the body tag. I came across a posting here utilizing this code:

function THEMENAME_preprocess_html(&$vars) {
  $path = drupal_get_path_alias();
  $aliases = explode('/', $path);

  foreach($aliases as $alias) {
    $vars['classes_array'][] = drupal_clean_css_identifier($alias);

flushed all caches but my body tag still looks like:

<body class="html not-front not-logged-in no-sidebars page-node page-node- page-node-47 node-type-page section-content">

So instead of that page-node-47, I'd like to see 'about-us' or whatever the path or title of the page is. I guess the path would be a better option for a class name but I'm not picky on that matter right now.

I do have Pathauto and clean urls installed and working. And in my html.tpl, I do have this:

<body class="<?php print $classes; ?>" <?php print $attributes;?>>
  • Is your theme based on Omega? If not, have you checked that $path and $aliases contain what you expect? The code you've got wouldn't remove the page-node-# class (in case you were hoping it does), it should, in theory, just add a bunch of new classes
    – Clive
    May 29, 2015 at 18:32

2 Answers 2


I noticed that your function is named THEMENAME_preprocess_html(). If you don't have THEMENAME replaced with the name of your theme, the function won't be called and your classes won't get added.


@Richard yes, I have my theme name, neptune instead of "THEMENAME" and so, no @Clive I'm not using Omega but a child theme of Neptune.

so to check the $path and $aliases, do I just print those vars in the template.php (and then remove) as the correct way to get the values?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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