0

I recently changed a lot of URLs for SEO purposes and realized that all of my Facebook likes and Twitter tweet counts were lost on posts created prior to yesterday. Posts created since yesterday already had SEO-friendly URLs so I didn't have to change them and their social stats are of course, fine.

I used 301 redirects so I can still use the old URL in Facebook and Twitter code since they support indicating another URL to count.I know how to use custom fields in order to fix the old posts, but how do I do this when I have a mix of old posts with new URLs and new posts with unmodified URLs?

  • Isn't the answer entirely determined by how you are tracking your stats? And you did explain that part. – s_ha_dum Aug 31 '13 at 21:48
  • I'm not tracking any stats. A Facebook like action gets sent to Facebook, not stored in a local database. – annabwashere Sep 1 '13 at 5:59
0

Got it.

I was already using the Advanced Custom Fields plugin so I just created a custom field called "old_url" with that.

Then I created a function:

function sharingurl () {
    if(get_field('old_url') == "")
        {
            echo untrailingslashit(get_permalink());
        } else {                    
            echo get_field('old_url');
        }
}

Then I just included <?php sharingurl(); ?> in the data-href and data-counturl for Facebook and Twitter codes respectively.

Note: Facebook does not like trailing slashes, that's why I had to remove it from the permalink.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.