I have some PHP that ultimately says 'If this class is present in the HTML, add this string to the $additional_classes array'. Eg, something similar to:

$leftcol_empty = empty($content['leftcol']);
$additional_classes = !$leftcol_empty ? 'medium-8 medium-pull-4' : '';

Currently, I've put this at the top of my .tpl file and it works fine. However, I've been told I should move it to the 'theme preprocess function'.

I looked through my theme's template.php file and tried adding it to my_theme_preprocess_page, my_theme_theme and my_theme_process_html but it stopped working.

I've tried Googling for theme preprocesses but haven't found anything that works.

Would anyone know what preprocesses function I can use here?

  • 1
    You need to leverage the variables being passed and or add your own variable on ex. $variables['additional_classes'] then output that in the template with print $additional_classes;. The preprocess hook you are using depends on which template you want to add it to.
    – Kevin
    May 11, 2017 at 2:13

1 Answer 1


you can use theme_preprocess_html(&$variables) OR my_module_preprocess_html(&$variables)

in $variables you will see $variables['classes_array']

if(in_array('class_name', $variables['classes_array'])) {

  //Do your changes


Hope this will help.

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.