Really Simple SSL

How to recover Facebook likes after moving to https/SSL

Websites with a lot of Facebook likes are bound to lose some likes or shares when they move their site to https / SSL. Facebook sees your https URL as a completely different URL. How to recover your Facebook shares after you have switched to SSL?

On Stack Exchange and, I found a method that seems to work.

By setting the href attribute of the like button to your old (http) URL, the likes will get added to the http URL and at the same time, the likes for your http URL will be shown. The disadvantage of this solution is that new likes will still be added to the http URL instead of to the https URL. In the plugin I have created to fix this, this is solved by doing the replace only before the SSL switch time. This solution is not 100% reliable: in some cases, Facebook starts returning https shares even if you request the widget only with the http URL. In that case, the only solution is to use the API.

Plugin to recover your Facebook shares

We’ve created a plugin that handles this for you. If you don’t want to do the coding yourself, check out our shares recovery plugin. The plugin will also take into account the date you switched to SSL: the replacement to http:// will only be done on posts or pages that were created before you moved to SSL. This method gradually moves all likes to https. Also, some other widgets like AddToAny and Digg are supported. If you need any other widget supported, contact me, and if the widget uses a URL embedded in the code, I can probably add a fix. If your current tool retrieves the shares through the API, this is only possible if there are some hooks to hook into.

Recently we have also added a new feature: you can choose to enable the built-in sharing buttons in the plugin, which will enable the plugin to do the retrieval itself, for both http and https. The shares will be retrieved directly through the API for Facebook, Twitter, etc. As Twitter does not support share counts retrieval through the API anymore, the Twitter share retrieval is optional and uses a third-party method,, to retrieve the likes. The built-in buttons should be used instead of your current widget.

Manually recovering Facebook likes & shares

Really Simple SSL replaces all references to your domain to https automatically. To fix this, we can use a filter that is built into the plugin. We have to find something that is unique to the Facebook widget, so to fix all normal links, but not the Facebook links.

The Facebook widget uses code containing this:

<div class=”fb-like” data-href=”” …

Additionally, the og:url should be replaced.

We can use this to replace it back after the mixed content fixer has done its work (add to your functions.php):

function rsssl_recover_shares($html) {
    //replace the https url back to http
    $html = str_replace('property="og:url" content="','property="og:url" content="', $html);
    $html = str_replace('data-href="', 'data-href="', $html); 
    return $html; 

If you want to differ between posts before or after the SSL switch date, you can add some checks in this code based on the publish date of the post. This way you can recover shares for old posts, but use https shares for new posts.

$start_date = 'your switch to SSL date';
$publish_date = get_post_time('U', false, $post->ID);

if ($start_date && ($publish_date > $start_date)) {
//use https shares
} else{
//use http shares


Related articles

39 Responses

  1. We done this method, it works for a lot of urls but there are also a lot of urls that still don’t have the likes back. We used the option with the change-date. Any ideas why it doesn’t work for a large number of pages/urls?

    1. If you suspect the date condition is not working properly, I would test what happens if you remove the date condition. If that works, then it’s better to remove the date condition, or to fine tune it so it starts working.

      1. Thanks for the reply Rogier. We tried removing the date condition but that did’nt help. How would you go into fine tuning? By changing the date?

        Do you think Facebook will solve the problem any time soon and give us our likes back? We had thousands of them on some articles and at least some on all the others. They all have zero now, which is very bad for us.

        1. This probably is a long standing issue, so I don’t expect any progress from Facebook.

          A user pointed out that in the example code here the end quote limits the replacements to exact matches of the string. So it should be:
          and not

          Maybe that will help in your case.

  2. Hi Rogier,
    I am in the process of migrating my sites from http to https.
    I lost the fb like counts too.
    Do I understand correctly that I have 2 options to recover them?
    -Use your plugin or
    -Add that code to the functions.php?

    1. It depends on what you are using for the share buttons. If you use the default FaceBook widget those are the two options. If you use a specialized sharing plugin, some of them have an option to count http and https shares. But this option might need a fix from my part as the mixed content fixer tends to fix all urls from the website’s domain to https.

      1. I am using the FB like button of the Add to Any plugin below my posts.
        Can I use your plugin or add that code to my funtions.php for that too?
        Will that work?

  3. Hello

    I have the same problem, and i use share button from Jetpack, where i put the code in functions.php from theme or in the jetpack ?

    Kind Regards

    1. For JetPack sharing buttons I would advise to use the plugin, which is enabled to fix the JetPack shares. The default Facebook code doesn’t work for JetPack.

  4. I used your Really Simple SSL plugin when we moved the site from http: to https. Worked great!

    Now we noticed that the FB Likes are gone. We use the AddToAny Share button plugin currently on the blog to display the social icons, including FB Share.

    If I purchase your plugin , will it work to get the FB likes back?

    Thank you!

      1. Hello, my website designer left the comment for me above. I use Firefox as my browser and over the course of a couple of days, the FB likes came back, went away, came back and now have gone again. Firefox has been acting strange lately and there was a very recent update as well. I decided to look at my blog in IE to see if the appearance was different. It was and all the FB likes are back to normal in the IE view. Maybe they never disappeared in the IE view. Not sure. Anyway, is there a way to get the FB likes to appear in all browser views? Thanks!

        1. It might be connected to caching. I’m not aware of any browser related issue with FaceBook likes. But it’s possible the way the likes are requested is different in different browsers.

  5. Hi, I added the code in functions.php but it didn’t solve the problem.
    I am using to count the shares. Do you have suggestions in my case?

    Thanks a lot!

    1. Hi Alberto,

      This code only works in combination with the Really Simple SSL mixed content fixer. If that is active, there should be a data-rsssl=1 visible in the page source. On your site I can’t see that at the moment. Have you activated Really Simple SSL? It could be that a caching plugin is blocking it if you do have it active. In that case you can try emptying the cache.

      Will it work with Sumo? That depends on how Sumo counts the likes, if Sumo uses the og:url then it might work. Currently your og:url is set to https://, you can change this to http://, enable Really Simple SSL, add the code to your functions.php and see if it works.

      Good luck and let me know if you have any other questions!

    1. I just looked through the code of that plugin, and I don’t think so. The plugin directly retrieves the likes from the source using the permalink, which will be https in your case, and there are no filters to override this behaviour. The only option you would have is to use the native sharing buttons in the plugin, which will make a summation of the likes for both http and https.

  6. I used the code above and got all of my Facebook like back on my Jetpack social share counts. Thanks!
    Now, can you tell em how to get my Pinterest counts back?

  7. Thank you very much for providing this fix.
    It seems ridiculous in 2017 that Facebook doesn’t care or can’t handle a https domain change by itself.

  8. Thanks for your greal plugin! help me alot
    i still try to figure out few small issues, facebook comments is one, they were gone, tried to insert the code here but it didnt restore it.
    i use facebook comments plugin
    also tried to change the url on Facebook App to https i dont know if its needed.
    do you have a solution?

    1. Hi Daniel,

      we don’t have a lot of experience in retrieving Facebook comments. If the code didn’t work, that’s probably due to the way the Facebook comments plugin retrieves the comments from Facebook. You could try if using another plugin solves this issue, the comments should be retrieved for both the http:// and https:// domains.


      1. Thanks! i just figured out Fix you can also share for those who have problems, my domain is showing without www so if i remove it from the code like this its worked for me and restored my comments:)

        function rsssl_exclude_http_url($html) {
        //replace the https url back to http
        $html = str_replace(‘data-href=”’, ‘data-href=”’, $html); return $html;

        anouther issue i cant figure out and maybe you can help is the RSS feed, i try to get RSS feed from anouther website to the website that just moved to SSL and i get error:
        RSS: WP HTTP Error: cURL error 60: server certificate verification failed.

        1. Hi, thank you for this solution. If I change from to (without the www), would I have to use the code like this:

          function rsssl_exclude_http_url($html) {
          //replace the https url back to http
          $html = str_replace(‘data-href=”’, ‘data-href=”’, $html); return $html;

          Will this work? Thank you.

  9. Hi guys,
    The plugin and snippet are for wordpress. Can I get it right? How about moodle? How to recover Facebook likes and shares in moodle?

    1. Hi Phoenix,

      I’m not sure how to do that in Moodle, Really Simple SSL is for WordPress only, you might have better luck contacting the Moodle support team.


    1. Hi Udi,

      have you activated Really Simple SSL? The plugin needs to be activate for this to work. After activating the plugin you can try to change the og:url to http://, that might do the trick.


  10. Hi there, thanks for this solution!

    but, is possible that doesn’t works with WP 4.9.6?
    …after applying to functions.php, both, og:url and FB data-href=” still present the https:// prefix

    Thanks for your answer

    1. Hi,

      the code should also work with WordPress 4.9.6. Can you check if the quotes (“”) are copied correctly? Sometimes when copying/pasting these they turn into different quotes (””) which causes the code to fail.


      1. Hi Mark,
        I’m using the standard, straight version, quotes: \0027 for single ‘ and \0022 for double “,
        not the “curly” ones (\201C and \201D)
        but when I activate the plugin (or manually edit .htaccess, or manually change from http:// to https:// in WordPress General Settings), all the website generated output contains only https:// references (also trying to modify og:url or rel=canonical with others snippets, for SEO plugins, or manual attempts)

        thanks again

        1. Hi,

          it is possible that the site is serving a cached page which still contains the https:// urls. Have you tried clearing all caches the website uses? Really Simple SSL needs to be active before the replace script works, can you check if the ‘data-rsssl=1’ marker is present in the page source? This indicates that the plugin is active and is replacing http:// to https:// on your site.



          1. Hi Mark, thanks for helping,
            I’m not using caching plugins (only some Expire Headers and Cache-Control Headers in .htaccess), btw I can normally see effects of other changes in function.php, if make some.
            this is what appears in the page source after activating Really Simple SSL.
            But I’ve noticed something interesting (when the site is running in https): after editing functions.php and getting “File successfully updated” message, checking again the content I find that the snippet text I’ive inserted is altered… both “http://” instances are changed in “https://”.
            So, str_replace function is replacing “https://…” with “https://…” and, obviously, nothing changes!
            I’m a newbie, I suppose there is something I’m missing, but I can’t understand what!

          2. Hi,

            when http:// is changed in https:// there might be something wrong with the code, it should work the other way around. What happens when you switch the https:// and http:// in the code?


  11. I have added the code in the functions.php of my theme. But it is still showing zero count for facebook. Ki dly tell me Where should I add the code in functions.php.
    Should I have to something extra. I have already activated your plugin.

    1. Hi,

      it doesn’t matter where in the functions.php file you put the code, you can try to put it right after the opening https://. This needs to be replaced to http:// as well. Can you check it the og:url is http://?


Leave a Reply

Join our mailing list - 8 Tips & Tricks in your inbox over the next 8 weeks!

Integrate with Really Simple SSL

Really Simple SSL offers a Free SSL Certificate from Let’s Encrypt. Do you want to integrate with Really Simple SSL as a hosting provider? Let us know!

Choose the answer that most closely resembles your proposed integration. Additional information can be entered below.
After sending the form. The pop-up will close automatically.