How to Preserve Social Shares When URLs Change in WordPress With Digg Digg

How to Preserve Social Shares When URLs Change in WordPress

Have you changed your website’s URL structure in WordPress?

Did your social shares disappear?

This past year, I worked on two WordPress websites that went through major URL changes. With each URL change, the social shares on blog posts disappeared. I knew this would happen, but the reality of losing those social share counts and social proof were not a welcome byproduct to the website owners.

I made is a mission to try to fix the problem. In this article, I will be sharing:

  • How to preserve social shares after changing from WordPress’ default URL structure to pretty links with Digg Digg by Buffer.
  • How to preserve social shares after changing URLs to HTTPS with Digg Digg by Buffer.
  • How to troubleshoot insecure items after changing to secure HTTPS in Digg Digg.

What is Social Proof?

Social proof is a psychological phenomenon of positive influence when people assume that the behavior of others is the correct behavior.

For example, have you ever looked up a movie on Rotten Tomatoes or Metacritic to see how others scored it before going to see it? Were you influenced by the ratings that other people made on that movie?
Or, do you read the product reviews on Amazon before making a purchase? Do those reviews sway your opinion on whether to buy or not buy the product?

If you do check online reviews before making a purchase, you are not alone. The study, Local Consumer Review Survey 2014, by BrightLocal showed:

  • 88% have read reviews to determine the quality of a local business.
  • 72% of consumers will take action after reading a positive review.

In the same way, the higher number of social sharing counts on the social media buttons on your website act as an influence on others that your content is valuable.

When people see that others have liked and shared your content, those numbers give more credibility. In turn, when those numbers disappear, it looks like no one has liked or shared your content. Viewers may be psychologically influenced when seeing higher share counts on your social sharing buttons as proof that your content offers value.

Preserving Social Shares After Changing from WordPress’ default URL structure to Pretty Links with Digg Digg by Buffer

The Challenge:

The first website that I worked on changed the URL structure in a WordPress website from the default URL structure links to pretty links. Changing the URLs resulted in all the social shares numbers to disappear in Digg Digg by Buffer.

Here are examples of the WordPress default URL structure and a pretty link:

  • Ugly link: https://r-rwebdesign.com/?p=4734
  • Pretty link: https://r-rwebdesign.com/top-social-media-trends-2015

The Solution:

The solution for keeping your social share counts after changing to pretty links in WordPress is a slightly modified version of the fix by João Garin. The fix is to keep the “old URL” when the URL has changed:

  • Locate the digg-digg.php file in wp-content/plugins/digg-digg
  • Copy the code below between the green commented out lines and insert it at line 46 under the line of code:
    $title = trim($post->post_title); // get post title
  • Edit the number in the following (indicated in red) $url_change_id = “4379“; to the post number of your last post before you changed the URL structure.
  • Check line 51: $url_id_postfix = “blog/?p=” . $post_id; to be sure that your path is correct. If your blog posts are on the root level, you will want to edit this to /?p=”
  • Finally, change the $sharing_url to your URL.
global $wp_query;
$post = $wp_query->post; //get post content
$id = $post->ID; //get post id
$postlink = get_permalink($id); //get post link
$commentcount = $post->comment_count; //get post comment count
$title = trim($post->post_title); // get post title
 //SOCIAL SHARING FIX BY JOAO
$sharing_url = get_permalink();
$url_change_id = "4379";
$post_id = $id;
if ($post_id < $url_change_id) {
$url_id_postfix = "blog/?p=" . $post_id;
$sharing_url = "http://r-rwebdesign.com".$url_id_postfix;
 }
//END SOCIAL SHARING FIX BY JOAO
$link = explode(DD_DASH,$postlink); //split the link with '#', for comment link
$url = $link[0];
$url = $sharing_url;

Preserving Social Shares After Changing URLs to HTTPS with Digg Digg by Buffer

The Challenge:

In August 2014, Google announced that HTTPS would be a ranking signal. While this announcement about Google’s HTTPS ranking signal may be an unwelcome change by some, the purpose behind the new ranking signal is security. Those that comply may get rewarded in the search results.

The migration to HTTPS from HTTP also causes social sharing counts to disappear in Digg Digg social sharing buttons. URL examples:

  • Non SSL link: http://r-rwebdesign.com/seo-fundamentals
  • SSL Link with HTTPS: https://r-rwebdesign.com/seo-fundamentals

The Solution:

The solution for preserving your social proof numbers after changing URLs to HTTPS in Digg Digg is a modified version of the same fix by João Garin. Again, the fix is to keep the “old URL” in Digg Digg when the URL has changed.

  • Locate the digg-digg.php file in wp-content/plugins/digg-digg
  • Copy the code below between the green commented out lines and insert it at line 46 under the line of code:
    $title = trim($post->post_title); // get post title
  • Edit the number in the following (indicated in red) $url_change_id = “5695“; to the post number of your last post before you changed the URL structure.
  • Be sure to edit line 54 and 55 with your domain name
global $wp_query;
$post = $wp_query->post; //get post content
$id = $post->ID; //get post id
$postlink = get_permalink($id); //get post link
$commentcount = $post->comment_count; //get post comment count
$title = trim($post->post_title); // get post title
//ORIGINAL FIX FOR MIGRATING TO PERMALINKS BY JOAO 
//Modified by R & R Web Design LLC to preserve social shares after
//migrating to https
$sharing_url = get_permalink();
//First post id after changing to https
$url_change_id = "5695";
$post_id = $id;
if ($post_id < $url_change_id) {
 $url_id_prefix = "https" . $post_id;
 $sharing_url = str_replace("https://r-rwebdesign.com",
"http://r-rwebdesign.com",	
$sharing_url);
}
//End Social Sharing Preservation Fix
$link = explode(DD_DASH,$postlink); //split the link with '#', for comment link
$url = $link[0];
$url = $sharing_url;

Troubleshooting Insecure Items After Changing to Secure HTTPS in Digg Digg

After initially changing the URLs to HTTPS, I noticed that the “padlock” on older posts indicated that some of the items on the pages were insecure.

First, I checked a post with Why No Padlock and located the code in the dd-class.php file Digg Digg file. That file is located at:

wp-content/plugins/digg-digg/include/dd-class.php

There are 24 different social sharing options in Digg Digg, so you will need to locate the code for the appropriate social network that is causing an insecure session. For example, Why No Padlock identified the following JavaScript file as insecure:

Why No Padlock Results

Next, I looked for that code in the file:

dd-class.php

On lines 384 and 385, I edited the insecure URL by adding the “s” to the http as indicated in red below.

 const BASEURL_LAZY = '<a href="https://bufferapp.com/add" class="buffer-add-button" data-count="VOTE_BUTTON_DESIGN" data-text="VOTE_TITLE" 
data-url="VOTE_URL" data-via="VOTE_BUFFER_SOURCE"></a>';
 const BASEURL_LAZY_SCRIPT = "function loadBuffer_POST_ID(){ jQuery(document) .ready(function(\$) { \$('.dd-buffer-POST_ID').remove();\$.getScript
('https://static.bufferapp.com/js/button.js'); }); }";

Conclusion

Preserving social share counts when changing your URLs in WordPress can be accomplished through a few minor edits to the plugin Digg Digg by Buffer.

I did find an inconsistency in the Pinterest and Facebook share numbers after changing to the HTTPs URLs. For Twitter, Buffer, Google Plus and LinkedIn, the numbers were preserved successfully.

You should also be aware that the old URLs will be shared going forward for the pages before the URL change after using either of these methods.

Your Turn

Have you ever changed the URLs on your WordPress blog or website? Do you plan to in the future considering Google’s HTTPS algorithm ranking factor?

I would love to hear your thoughts and if you have any questions.


Update:
A new favorite social sharing plugin offers the ability to recover social shares when changing URLs. For more, please see:


Fascinated with the growing potential and power of the Internet, Robin founded R & R Web Design LLC in the Chicago area in 2000. As creative director, she is passionate about helping others reach their Internet objectives through a strategic online presence with results driven custom web design, ethical SEO, and social media marketing.

12 comments on “How to Preserve Social Shares When URLs Change in WordPress With Digg Digg
  1. This is pure gold! Thanks so much for solving this problem, Robin. It’s great to know that website owners can still use the popular plugin Digg Digg without losing social shares when migrating to SSL or changing permalinks. I will gladly be sharing this helpful post!

    • Michelle,

      It is my pleasure, Michelle. I’m happy to hear that you like the solution to the problem, Michelle. Losing social proof numbers can be devastating when migrating to SSL or changing permalinks. With Buffer’s Digg Digg and a few edits, we can now preserve them. Thank you for sharing this!

      ~ Robin

  2. Hi Robin,

    You have wowed me with this post! It is great to know how to fix this problem if one wants to change. I know many who are going through changes and this post is the answer for them!

    I must admit it is way over my head, technically speaking, but I could understand the gist of it. I haven’t changed anything so far, nor I think I will in the future, but if I did I have the magic bullet here that I did copy and paste to my Evernote for those “Just In Case” times.

    Meanwhile, I know this is great value for those who are struggling. It is a great share and you know I’m going to blast this out.

    Thanks!

    -Donna

    • Hi Donna,

      You have made my day! I know that this is a bit technical. With Google strongly encouraging website owners to switch to HTTPS for a safer Internet, there will be others that will want to keep their social sharing numbers. Hopefully, this will help others that are struggling with URL changes.

      I appreciate you stopping by, for your encouraging words, and for sharing this!

  3. Adrienne says:

    Hey Robin,

    I’ve had this issue in the past when I changed from Digg Digg to another social sharing plugin. Now I’m told it won’t be supported any longer and I’m going to have to find another one. I’m freaking out that all my social shares may disappear once again and I’ll have to start over.

    Does this work for other plugins do you know? These plugins come and go, they quit working and we have to find new ones so when this issue continues to arise we definitely need a fix.

    Thanks so much for this post and I sure hope you have a positive answer for me. 😉

    ~Adrienne

    • Hi Adrienne,

      I’m sorry to hear that the social sharing plugin that you are using will no longer be supported and that you will have to find a new one. This is a real concern. I wish there was an across the board solution, but presently, there is not. I haven’t worked on the programming of any other social sharing plugins, but if I do, I will definitely let you know.

      Thank you for stopping by! It is always a pleasure to have you visit.

      ~ Robin Strohmaier

  4. Hey Robin,

    I wish I would’ve known this last year when I changed my permalink! There were a couple of posts where I had over 400 shares within a short time and once I change the link, they all disappeared.

    I do have a question though.. does this only work with Digg Digg or will it work with other social share plugins? I use Flare.

    • Hi Sherman,

      I’m sorry to hear about the 400 social shares that you lost when you changed URLs. I can image how frustrating that is.

      As for preserving social shares with Flare, I haven’t tried working on the programing on it to do this. I do hope to work on a few others to see if it is possible. I will definitely let you know.

      Thank you for stopping by and for your comment!

      ~ Robin

  5. Hi Fabio,
    It looks like you may have figured this out. I checked one of your blog posts and it is showing the social share counts.
    ~ Robin

    • Fabio says:

      I don’t know why my last comments wasn’t posted. In any case, the thing is that the counters seemed to be ok but now Facebook counter has returned to 0 in the old posts, while Twitter and Google + counters are still working. What could be the reason?

    • Hi Fabio,

      Please review the first script example above and try:

      //SOCIAL SHARING FIX BY JOAO
      $sharing_url = get_permalink();
      $url_change_id = “2570”;
      $post_id = $id;
      if ($post_id < $url_change_id) { $url_id_postfix = "/wordpress" . $post_id; $sharing_url = "http://eatandlovemadrid.es".$url_id_postfix;

Leave a Reply

You have to agree to the comment policy.

*

By signing up or submitting a comment you are agreeing to our Privacy Policy.