Skip to content

Instantly share code, notes, and snippets.

@epicdaze
Created July 2, 2011 04:47
Show Gist options
  • Save epicdaze/1059744 to your computer and use it in GitHub Desktop.
Save epicdaze/1059744 to your computer and use it in GitHub Desktop.
#wordpress - tweet button with hashtags #twitter #tags #hashtags #whitespace
<!-- /* Twitter button: post title and post tags. Prepend tags with hash symbol and remove whitespace within tags. */ -->
<a href="http://twitter.com/share"
class="twitter-share-button"
data-url="<?php bloginfo('url'); ?>/<?php the_ID(); ?>"
data-text="<?php the_title();
// remove whitespace inside tags and prepend with #
$tags = get_the_tags();
$tags_hashed = array();
foreach((array)$tags as $tag)
$tags_hashed[] = str_replace(' ', '', $tag->name);
echo ' #'.implode(' #', $tags_hashed); ?>"
data-count="horizontal" data-via="twittername" data-lang="en">Tweet</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<!-- /* Tweet will look like this: */ -->
Post title #tag #anothertag http://domain.com/42 via @twittername
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment