How to add a CSS class to some certain pages depending on the path alias? I'm trying to add a CSS class to some certain pages for some certain menu styling depending on the current alias path. It works well with the following function but I'm wondering is there another way to split the current alias parts so I can use them as arguments? Here's my present function:

function mytheme_preprocess_html(&amp;$vars) {

  $path = drupal_get_path_alias($_GET['q']);
  $aliases = explode('/', $path);

  if (isset($aliases[2]) &amp;&amp; $aliases[2] === 'foo') {
    $vars['classes_array'][] = 'bar';
  }
}
You should be using Drupal's arg function:
https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/arg/7

Something like this should work:

function mytheme_preprocess_html(&amp;$vars) {

    if (arg(2, drupal_get_path_alias()) == 'foo') {
        $vars['classes_array'][] = drupal_clean_css_identifier(arg(2, drupal_get_path_alias()));
    }
}


Added drupal_get_path_alias() as an arguement of arg() as suggested by @koivo