Hello,

I have a Facebook like button on my homepage and some individual pages. My code is:

<script src="https://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:like href="http://www.mydomain.com<?=$_SERVER['REQUEST_URI']?>" layout="button_count" show_faces="false" width="100" action="like" font="arial"></fb:like>

However, the total count is different from homepage and individual pages. So, how do I add a total count to make it more attractive (I mean bigger number).

For example, homepage has 10 likes, individual pages have 10, can I add them up to make it 20 likes that show on everywhere of my site?

Thanks.

Dani AI

Generated

Quick summary and practical choices (for ): the Facebook Like counter is tied to the exact URL used by the widget, so the homepage and individual pages will show different numbers unless they point to the same href. That explains the discrepancy seen in the thread; several replies suggested plugins to hide that complexity, which is a fine short path, but the underlying options are two-fold: 1) make every Like button point to one canonical URL (site root or a dedicated Facebook Page) so the same total appears everywhere, or 2) compute an aggregated total server-side (query Facebook for each page’s counts and sum them) and display that single number in the theme. (webmasters.stackexchange.com)

Server-side aggregation (simple pattern)

  • Use the Graph API URL node (request the engagement fields) for each page URL, extract the field(s) wanted (for “likes” use reaction_count; share_count and comment_count are separate), sum them and cache the result. Example (PHP, minimal):
$urls = ['https://example.com/','https://example.com/post1']; 
$token = 'APP_ID|APP_SECRET';
$total = 0;
foreach ($urls as $u) {
  $api = 'https://graph.facebook.com/?id='.urlencode($u).'&fields=engagement&access_token='.$token;
  $data = json_decode(file_get_contents($api), true);
  $total += isset($data['engagement']['reaction_count']) ? (int)$data['engagement']['reaction_count'] : 0;
}
echo $total;

The engagement object is the documented field to inspect; it returns reaction_count, share_count, comment_count, etc., and many community examples use the fields=engagement call with an access token. (stackoverflow.com)

Notes, pitfalls and best practices

  • Normalize URLs before querying (canonical URL, consistent scheme, strip session/query noise).
  • Cache aggregated totals (hourly or longer) to avoid hitting Facebook’s public-data limits — Facebook enforces tight per-URL/app rate limits and may return coarse/empty values under low counts. Refresh from Graph API asynchronously (cron) and store the cached total for display. (stackoverflow.com)

Mention: plugin suggestions from , and will automate many of these steps (normalization, caching, batching). For full control, server-side aggregation plus caching is the robust route; pointing all Like buttons to one canonical URL is the simplest.

there is plug in, called "add this" it for sharing purpose that also give you stats of your share and like.

Remove the code and gain add the code that you want to applied.either you can add plugins that helps you alot.

There are plenty of free plugin available for it. we need not to worry about it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.