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
Lightweight plugin, Heavyweight Security features. Get Pro and leverage your SSL certificate for WordPress security standards.