Search code examples
ssladdthissocialshare

Moved to SSL, lost my social sharing button counts, now need to use the old http url to get them back


I just switched my site over to SSL and all of my social sharing button counts have reset to zero, which is expected, but apparently it's possible to tell those buttons to use the old http urls in order to bring back the old counts.

I just can't figure out how to do it for my setup, which is AddThis for the buttons and Php/Html for the code (Joomla actually, but that may be irrelevant).

The AddThis code is simple:

<div class="addthis_sharing_toolbox" data-url="THE URL"></div>

So my best guess is that I need to take the current URL, change it from https to http, and plug it into the above 'data-url'.

But looking at other threads here, there seems to be a lot of controversy about how to securely and correctly get the current URL, so that's where I'm getting stuck.

(And then on top of that, I'll need to make this switch only for past articles, not new ones, but that's another story.)

Any ideas?

Thanks very much, Phil


Solution

  • Took me all day, but I finally figured this out! This gave me a lot of the answer, but I still had trouble tweaking it for AddThis.

    Here's the code (the first line applies the fix only to articles published before Aug 1, 2016, because I don't need to make the change for newer articles):

    <?php if (strtotime($this->item->publish_up) < 1470009600) : ?>
    <script type="text/javascript">
    function buttons(){
    var kCanonical = document.querySelector("link[rel='canonical']").href;
    window.kCompositeSlug = kCanonical.replace('https://','http://');
    return;
    }
    buttons();
    var addthis_share = { url: ''+kCompositeSlug+'' };
    </script>
    <?php endif; ?>
    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ID-GOES-HERE" async="async"></script>