i need to add another class to message div. That class must be the name of the module that creates the message.

Example: A new mail is added via "Simple suscription" module. Then the message div should be "div.error.simple_suscription"

I need this since i have, contact/comment form within #main, and the #footer has a form for newsletter suscrptions. Plus i'm making images for the messages.

Thanks for your time.


as described here you can add your classes to message div:

drupal_set_message(t('Something horrible just happened.'),'error simple_suscription');
|improve this answer|||||
  • 1
    Thanks sheena_d and Mohammad Ali Akbari. I just added the class to my "simple suscription" module. That's all! many thanks. – Federico Arena Apr 30 '12 at 19:53
  • I tried using the above code but its not outputting the custom class – redamakarem Jul 6 '17 at 20:42

The theme function that handles the HTML output for system messages is theme_status_messages()

Unfortunately, the API function that modules use to set status messages, drupal_set_message(), does not collect any information about where the messages originate. Thus, there is no way to add module-specific classes to a system message when it is themed. The only option is to add the class when the message is created via the $type variable in drupal_set_message().

I do not see any reasonable solution if you are hoping to use this technique for all messages on a site and/or messages from core or contrib modules.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.