Tag: tutorial
Integrate Twitter Buttons in WordPress (with shortened URL)
How to create a “tweet this” button for your blog post in WordPress? You have many options.
Twitter has become a social network sharing system and you should always provide an easy call-to-action for your readers to share your posts. Also, don’t forget to shorten your URL.
The TinyURL Way
There’s a great tutorial on Smashing Magazine. However, the specific code I am providing is modified to work with MediaTemple since MediaTemple doesn’t support file_get_contents. If you use the code on smashing magazine you will get a Warning: file_get_contents() …
Put this code in your function.php file
// Create TinyURL for post to Twitter
function getTinyUrl($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, ‘http://tinyurl.com/api-create.php?url=’.$url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$tinyurl = curl_exec($ch);
curl_close($ch);
return $tinyurl;
}
and in your single.php or wherever you want your “Tweet this” button to show up, put in this code:
<a href=”http://twitter.com/home?status=Reading%20@yourusername%20′<?php _e(urlencode(the_title_attribute(‘echo=0′))); ?>’%20@%20<?php … Read More »