Seo

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 complete different url. How to recover your Facebook shares when you have switched to SSL?

On Stack Exchange, and searchenginewatch.com I found a method which 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, but 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’ve created to fix this I’ve solved this 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 replace to http:// will only be done on posts or pages that were created before you moved to SSL. This way you will gradually move all likes to https. Also some other widgets, like add to any, and digg 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, opensharecount.com to retrieve the likes. The built in buttons should be used instead of your current widget.

Warfare plugin

If you are using the social Warfare plugin, they have a plugin optimized for the Social Warfare plugin (Please note, this is an affiliate link) that recovers the Facebook, Twitter, and other likes and shares.

Manual way

Really Simple SSL replaces all references to your domain to https automatically. To fix this, we can use a filter that’s 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=”http://www.domain.com” …

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 in your functions.php):

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

Related Articles

31 Comments

  • Sanne

    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?

    • Rogier Lankhorst

      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.

      • Sanne

        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.

        • Rogier Lankhorst

          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:
          ‘data-href=”https://www.domain.com’
          and not
          ‘data-href=”https://www.domain.com”‘

          Maybe that will help in your case.

  • Johanna Ouwerling

    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?

    • Rogier Lankhorst

      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.

      • Johanna Ouwerling

        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?

        • Johanna Ouwerling

          I just added the code to the functions.php. That works like a charm. Thanks so much for this!

  • Fernando Agostinho

    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

    • Rogier Lankhorst

      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.

  • Lisa Johnson

    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!

    • Rogier Lankhorst

      That should work. In some cases you need to enable the og:url option in the settings.

      • Lisa Johnson

        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!

        • Rogier Lankhorst

          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.

  • Stephen

    Hi Rogeir, I am thinking I have found the solution with your plugin. Does this work for those of us Using Add This?

    • Rogier Lankhorst

      Yes, it works for add this as well.

  • Alberto

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

    Thanks a lot!

    • Mark Wolters

      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!

  • Christian Wilde

    Hi Rogier, I’m Using Really Simple SSL. Will Really Simple SSL Social work with Cresta Social Share Counter?

    • Rogier Lankhorst

      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.

  • Rachel Lynn

    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?

  • Ric

    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.

  • Daniel Sas

    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?
    Thanks:)

    • Mark Wolters

      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.

      Mark

      • daniel sas

        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=”https://domain.com’, ‘data-href=”http://domain.com’, $html); return $html;
        }
        add_filter(“rsssl_fixer_output”,”rsssl_exclude_http_url”);

        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.

        • Mon

          Hi, thank you for this solution. If I change from http://www.mydomain.com to https://mydomain.com (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=”https://domain.com’, ‘data-href=”http://www.domain.com’, $html); return $html;
          }
          add_filter(“rsssl_fixer_output”,”rsssl_exclude_http_url”);

          Will this work? Thank you.

          • Mark Wolters

            Hi Mon,

            yes, that would be correct.

            Mark

  • Phoenix Ng

    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?
    Phoenix,

    • Mark Wolters

      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.

      Mark

  • Udi Burg

    Well, didn’t work for me 🙁

    • Mark Wolters

      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.

      Mark

Leave a Comment