Monday, 21 August 2017 09: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:
http://www.yoursite.com/the-page-you-are-sharing

When you switch to SSL / HTTPS, your URL changes, similar to if your domain name changes altogether:
https://www.yoursite.com/the-page-you-are-sharing

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 273 times Last modified on Monday, 21 August 2017 09:30

Leave a comment

Make sure you enter the (*) required information where indicated.
Basic HTML code is allowed.

Copyright © 2005-2016 Covington Creations, LLC | Hosting by InMotion | Legal