I want to rewrite the link text for Flags such that it includes the number of flaggings for that node, as pluralizing the output.


  • 1 Flag
  • 3 Flags

I can get as far as getting the flag count and pluralizing the output using a field rewrite, but the Ajax link breaks, and the field can no longer be clicked to flag or unflag the node.

I've tried the dlike module, but this doesn't seem help with pluralizing the flag/unflag link

2 Answers 2


I found I was able to do this by changing the flag link text (in the flag configuration) to [node:flag-machinename-vote-count], which gave the number of flag for that node.

Then, modifying line 57 of the flag theme file: flag.tpl.php to

<a href="<?php print $link_href; ?>" title="<?php print $link_title; ?>" class="<?php print $flag_classes ?>" rel="nofollow"><?php print format_plural($link_text, '1 Flag', '@count Flags') ; ?></a><span class="flag-throbber">&nbsp;</span>

Note that this is actually only changing the small php snippet that displays the link text to us the format_plural function:

this <?php print $link_text; ?>

to this <?php print format_plural($link_text, '1 Flag', '@count Flags') ; ?>


Put the code below in your views Global:PHP field

print flag_create_link('your-flag-machine-name',$row->uid);(\

$counts = flag_get_counts('user', $row->uid);

//note in my case i have to add flag links on user profiles
//change according to your need here, say('node', $node->nid).

if ($counts['your-flag-machine-name'] == 0) {
  echo 'please vote first!!';

if ($counts['your-flag-machine-name'] == 1) {
  echo $counts['your-flag-machine-name'] .' Like';
else {
  if ($counts['your-flag-machine-name'] >= 2) {
    echo $counts['your-flag-machine-name'] .' Likes';
  • Thanks Vikram - I couldn't actually get this to work, but managed another solution.
    – Simo
    May 21, 2016 at 11:27

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.