Skip to content

Instantly share code, notes, and snippets.

@epicdaze
Created July 3, 2011 19:24
Show Gist options
  • Save epicdaze/1062523 to your computer and use it in GitHub Desktop.
Save epicdaze/1062523 to your computer and use it in GitHub Desktop.
#wordpress - valid twitter share button #twitter #share #tags #documentwrite #whitespace
<!-- /* customized and valid twitter share button using asynchronous document.write */ -->
<!-- /* inspired from http://techoctave.com/c7/posts/40 and gist:1059744 and gist:1059498 */ -->
<script type="text/javascript">
//<![CDATA[
(function() {
document.write('<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="twitter_username" '
+'data-text=\'Article#<?php the_ID(); echo": "; the_title(); $tags = get_the_tags(); $tags_hashed = array(); foreach((array)$tags as $tag) $tags_hashed[] = str_replace(" ", "", $tag->name); echo " #".implode(" #", $tags_hashed); ?>\' '
+'data-url="<?php bloginfo('url'); ?>/<?php the_ID(); ?>" data-lang="en">Tweet this</a> ');
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript'; s.async = true; s.src = 'http://platform.twitter.com/widgets.js'; s1.parentNode.insertBefore(s, s1); })();
//]]>
</script>
<!-- /* sample output: */ -->
Article#3141: Lorem ipsum dolor sit amet #tag #anothertag http://domain.com/3141 via @twitter_username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment