How to keep social share counts after migrating to SSL

When you migrated your website to SSL protocol (from http to https), you probably noticed that you had lost all your previous share counts. How to keep them?

We can think on different approaches for them.

Main point: Unfortunately it is not possible via social networks APIs themselves. That’s why we need some tricks.

Here is how i solved this problem and retained back to my old posts’ social share counts.

I am using custom embed codes for social share buttons. Here is facebook embed code i am using:

Now we need to apply our trick and to retain old share counts.

Here is the logic:
1. We remember the date we migrated to SSL.
2. We check if current post was published before or after that date.
3. If it is published before that date, we pass Facebook our URL with HTTP version, in order to save old share counts.

That’s all.
I have migrated to SSL at 20th May, 2018. That’s why i check if post_date is greater or less than 2018-05-20 06:30:03, if it is less, then i change HTTPS to HTTP.

 

Before:

After:

It is possible to apply same logic to other social network embed codes.