Thomas G. Bennett, Inc. - - Websites, Marketing, Maintenance, and Hosting logo

Go to:

  • About
  • Our Work
  • Services
    • StoryBrand Website Design
    • Website Design & Development
    • Search Engine Optimization
    • Conversion Rate Optimization
    • Hosting
  • Schedule a Call
  • facebook
  • twitter

You are here: Home › Website & Marketing Blog › Updating the Permalinks – Fixing Your Social Sharing Count

September 13, 2012 Comments are off

If you’ll remember, WordPress updated its permalink structure back around version 3 or 3.1. Prior to this a lot of folks were using the /%category%/%postname%/ structure. It was really slow and caused an excess amount of queries in order to generate the pages, so WordPress began pushing for the /%postname%/ structure.

This morning I had to go in and make this change on a friend’s blog that I’ve done some work for and he quickly pointed out that all of his social sharing counters were gone. His 100+ Facebook likes and Twitter tweets had disappeared from each of his posts.

The problem was that the posts were looking at the urls with the category in them and one those urls were removed it though those new pages (new urls) had not been shared. There is an article out there that explained how to replace the url that was built with dates but I had to modify the code a bit in order to solve the issue for of replacing the /%category%/ section in the URL structure.

I thought I’d paste that code in case it helps anyone else.



// date we swapped the permalinks
$url_change_date = strtotime("9/12/2012");

// date $post->ID is published
$date_posted = strtotime(get_the_date());

// get page link
$sharing_url = get_permalink();

// if post published before permalinks were changed
if ($date_posted < $url_change_date):
$category = get_the_category($post->ID);
$category_slug = $category['0']->category_nicename;

// replace the new share URL with the old share URL IF created before permalinks were changed
$sharing_url = str_replace('://yourWebsiteUrl.com/', '://yourWebsiteUrl.com/' . $category_slug . '/', $sharing_url);
endif;

For implementation just be sure to replace where your URL is being displayed inside your Like/Tweet/Google+ code.

<p><a href="http://twitter.com/share" data-url="<?php echo $sharing_url; ?>" data-text="<?php the_title(); ?>" data-count="horizontal" data-via="yourTwitterName">Tweet</a>
Read Next: The Ultimate Guide to eCommerce Product Page Design in 2018 (And Beyond)

suggested dosage by doctors fit patients, and 5mg of the elderly and malnourished people, as well as people with renal system failure. The drug is recommended to be taken

  • Best Warrior Competition
  • All Posts
  • Daily’s
  • About
  • Blog
  • Samples
  • Schedule Your Free Consultation
  • Give us a call: 615.678.2699

A StoryBrand Certified Guide

StoryBrand Certified Guide Top Web Designer in Franklin

Learn more about what we do

Bennett Web Group
231 Public Square, STE 300,
Franklin, TN 37064, United States
tel: 615.678.2699

Privacy Policy | Testimonials

Featured Marketing Articles

  • The Ultimate Guide to E-Commerce Product Page Design in 2019

    November 7, 2018

  • 24 E-commerce Best Practices Your Competitors Are Using (And You Should Too) [+Free Guide]

    March 14, 2018

  • The 10 Best E-commerce Marketing Strategies Of 2018 (Proven Guides)

    May 30, 2018