Skip to content

Instantly share code, notes, and snippets.

@Pleiades
Created November 15, 2012 23:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pleiades/4082392 to your computer and use it in GitHub Desktop.
Save Pleiades/4082392 to your computer and use it in GitHub Desktop.
Twitter Share button
function twitter( $atts, $content=null ){
/* Author: Nicholas P. Iler
* URL: http://www.ilertech.com/2011/07/add-twitter-share-button-to-wordpress-3-0-with-a-simple-shortcode/
*/
extract(shortcode_atts(array(
'url' => null,
'counturl' => null,
'via' => '',
'text' => '',
'related' => '',
'countbox' => 'none', // none, horizontal, vertical
), $atts));
// Check for count url and set to $url if not provided
if($counturl == null) $counturl = $url;
$twitter_code = << <script src="http://platform.twitter.com/widgets.js" type="text/javascript"><!--mce:0--></script>
<a class="twitter-share-button" href="http://twitter.com/share"></a>
HTML;
return $twitter_code;
}
add_shortcode('t', 'twitter');
Usage
There’s two uses for this shortcode. The simplest form is demonstrated below, that adds the counter-less button into your post.
[t url='get_permalink();']  
That was simple, no? If you want to add a counter, it’s only a parameter away and can be done in either of the vertical or horizontal configurations.
[t countbox="horizontal/vertical"]  
Finally, this last example lets you define which related accounts show up after you’ve tweeted, hopefully to help you grab yourself a few more followers.
. [t related='connorturnbull: Author, envatowebdesign: Sister Site']  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment