Monday, 21 August 2017 14:05

Solution for Lost Share Count after Moving to SSL / HTTPS

Written by 
Solution for Lost Share Count after Moving to SSL / HTTPS

I recently switched a client's site from HTTP to HTTPS (SSL encryption) and needed to come up with a solution to their "social sharing counts" resetting to zero.  This is not a flaw or bug, it's working as it was intended.  

Here is how it works.  When you share a page via social media, it uses its URL:

When you switch to SSL / HTTPS, your URL changes, similar to if your domain name changes altogether:

With the new URL, you lose all of your social sharing counts, a source of major pride (and potential profits).  

My solution (download TXT file) was to write a bit of PHP code that determines whether the article in question was posted before or after my SSL certificate was installed.  Note that this script uses Shareaholic as its example, but you can also adapt it for AddThis or whatever social sharing button service you like.  I saw that Shareaholic Pro accounts, and some premium (paid) share-plugin-developers offer solutions to this problem, but I'm not looking for another ongoing expense.  

I wound up writing my own code for this because other solutions (here, and here) used Javascript in their implementation and didn't seem as solid as my PHP method.  (download TXT file The way my code works is for non-SSL sharing button code section, it includes the 'data-link' command so that you can override the URL of the page being shared.  

In addition to using this code structure for fixing the share counts after adding SSL, you can also use this technique to change domain names, extensions, moving the site into a subdirectory, etc...

Read 2163 times Last modified on Thursday, 07 June 2018 15:34
0 #2 Nate Covington 2018-02-15 16:31
The code would go in your Wordpress / Joomla / Drupal theme or template files… in the PHP code.
0 #1 Vironika 2018-02-15 16:23
Hi there, where would I add this code?
Add comment