I want to add CSS classes to flagged nodes in order to theme them.

Found the documentation How to add CSS classes to nodes, based on flags set, but this solution is for D6.

Can someone help me to figure out how to make it work with D7?

  • Have you tried that code in your own yourtemplate_preprocess_node()? Jul 30 '13 at 20:58

Try this in your template.php of your theme. Change MYTHEME to the name of your theme and bookmark to the machine name of your flag. And change node-flag-bookmark to the css class you want to be added to your node.

 * Implements template_preprocess_node().
function MYTHEME_preprocess_node(&$variables) {
  $flag = flag_get_flag('bookmark'); // Machine name of your flag.
  if ($flag && $flag->is_flagged($variables['node']->nid)) {
    $variables['classes_array'][] = 'node-flag-bookmark';
  • 1
    Thanks, it worked! Class are added when you refresh the page. It is possible to add class without a page refresh? Jul 31 '13 at 10:43

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.