Retain your Social Proof after domain changes via AddThis and PHP
-
I thought I’d share this as it helped me to keep my social data counts.
Based on a post at this link, I built out a AddThis’s “data-url” to dynamically present the old domain for posts older that the cutover date. Newer posts remain unaffected:
<!-- Let's alter the domain based on post date --> <?php $url_change_date = strtotime("11/6/2015"); $post_date = strtotime(get_the_date()); $sharing_url = get_permalink(); if ($post_date < $url_change_date) { $url_date_prefix = "/" . date("Y", $post_date) . "/" . date("m", $post_date); $sharing_url = str_replace("://new-domain-name.com", "://old-domain-name.edu", $sharing_url); } // At this point, $sharing_url is the correct URL to present // to the social sharing APIs in order to maintain counters. ?> <div class="addthis_sharing_toolbox" data-url="<?php echo $sharing_url ?>" data-title="<?php the_title(); ?>"></div>
Note: be sure to include this code in both your single.php and index.php templates. See the original post mentioned above for a lengthy description of the issue.
- The topic ‘Retain your Social Proof after domain changes via AddThis and PHP’ is closed to new replies.