I need to add custom css classes to several blocks (can be blocks from view, or facet api, etc). Is there a way to do it without creating a template for every block? It could be useful a theme function, or a hook, that should do something like:

 if ($var == 'block_name') {
   $class_custom = 'my-custom-class';

Is it possible?

2 Answers 2


There's a template function for this: template_preprocess_block.

Use $variables['classes_array'] to add classes to the block.


You can also use the Block class project for the matter.

Block Class allows users to add classes to any block through the block's configuration interface. By adding a very short snippet of PHP to a theme's block.tpl.php file, classes can be added to the parent element of a block. Hooray for more powerful block theming!

  • 1
    I know that module, the problem is that has not support for features or generally a way to export configuration.
    – arrubiu
    May 21, 2013 at 7:00

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.