Seo

How to recover Facebook likes after moving to https/ssl

Websites with a lot of Facebook likes are bound to lose some likes when they move their site to https. Facebook sees your https url as a complete different url. A 301 redirect in your .htaccess, which seems to help keep Google Analytics hits, does not seem to work with Facebook. Maybe in the future, but for now, what to do?

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 url, the likes will get added to the old url, but also the likes of that old url will keep getting showed. Not the perfect solution, but it is a solution.

If you want to use this method, there’s one issue: 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.

Plugin way

I’ve created a plugin that handles this for you, if you don’t want to do the coding yourself, please check it out. The plugin will also take into account the date you switched to SSL: the replace to http will only be done on posts that were created before you moved to SSL. This will 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.

Recently I 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. If the aforementioned method fails, you can let the plugin retrieve the shares directly through the API for Facebook, twitter, etc. The twitter share retrieval uses third party method, opensharecount.com to retrieve the likes. These buttons are added instead of your current method.

Warfare plugin

If you are using the social Warfare plugin, they have a plugin optimized for the Social Warfare plugin that recovers the Facebook, Twitter, and other likes and shares.

Manual way

The FaceBook widget uses code containing this:

<div class=”fb-like” data-href=”http://www.domain.com” …

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

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

Related Articles

29 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.

  • 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