I want to add a body class for the content type of each node. Drupal already provides this, but it isn't always consistent between the Node view, the Node/Add view and the Node/Edit view. This makes theming difficult.
Here is my code in template.php
function MYTHEME_preprocess_html(&$variables) {
// Add Content type name to classes
$content_type = $variables['page']['content']['system_main']['type']['#value'];
$content_type_class = 'content-type-'.drupal_html_class($content_type);
$variables['classes_array'][] = $content_type_class;
}
It works but I get this error message:
Notice: Undefined index: type in wintheme_preprocess_html()
On Stack Exchange, it says the best approach is to use Isset()it says the best approach is to use Isset().
If I do this, the error message goes away, but so does the class.
How can I keep my class working without the error message.