I have a content type "Task" with a Date field to define a deadline for tasks. What I'm trying to do is to add an extra css class to the field wrapper to indicate that today is the deadline. I can do it with JQuery, but its stupid...

So i'd like create a function in my custom module which checks the field date, compares it with today date and if it results that today is a deadline (or the deadline already past), adds an extra class to the wrapper.

Will be very appreciate for any help or advice.

1 Answer 1


this might be what are looking for Adding CSS Classes to Fields in Drupal

Implementing any type of modular CSS requires fine grain control over classes in your HTML. In my last post, we looked at how we can easily add classes to blocks in Drupal using preprocess functions. Now let's apply the same technique to fields. Fields are a fundamental building block of any Drupal 7 site. Fields contain content and content is king. Before we dig in and start classing up our fields, let's look at how they are rendered to the screen.

  • Yes, hook_preprocess_field was exactly that i needed. Thanks a lot!
    – john
    Mar 8, 2015 at 10:25

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.