Skip to content

Instantly share code, notes, and snippets.

@jennschiffer
Created July 2, 2015 16:52
Show Gist options
  • Save jennschiffer/02cf38bef794ddd2d17a to your computer and use it in GitHub Desktop.
Save jennschiffer/02cf38bef794ddd2d17a to your computer and use it in GitHub Desktop.
Change blog url for Twitter button to save them sweet tweet counts
<h2>Twitter Button</h2>
<?php
/* bocoup.com was originally hosted across a number of subdomains. Since
* then, it has switched to organizing content with subdirectories. Construct
* the URL for the given item according to the site structure when the item
* was first published.
*/
function url_at_publication($id) {
$weblogPath = '/weblog';
$post = get_post($id);
$subdomainRemovalDate = new DateTime('2014-04-25 00:00:00');
$postDate = new DateTime($post->post_date);
if ( $postDate < $subdomainRemovalDate ) {
$url = 'http://weblog.bocoup.com/' . $post->post_name;
}
else {
$url = 'http://bocoup.com/blog/' . $post->post_name;
}
return $url;
}
?>
<a href="https://twitter.com/share"
class="twitter-share-button"
data-hashtags="bocoup"
data-text="<?php echo $post->post_title; ?> by <?php echo the_author_meta('display_name', $post->post_author); ?>"
data-counturl="<?php echo url_at_publication($post->ID); ?>"
>Tweet</a>
<script>
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment