preload
Jul 07

I wanted to make it as easy as possible for my blog readers to directly retweet my posts. First I started to install and test several WordPress plugins for this but I just couldn’t seem to find one that I liked. Some of them are to massive and are showing information about how many and who has retweeted your post, I don’t need that. Other required the Twitter Anywhere connection and the user must accept that the retweet application on my blog can connect directly to their Twitter account, I don’t want to force my readers to do this. I decided to create the Retweet functionality by myself so I would have full control on the behavior. This post will tell you step by step how to achieve this.

First I wanted to shorten the post url by using Bit.ly, I am not a php expert or familiar with the Bit.ly API so I googled and found the php code needed for using Bit.ly to shorten my url. I found a great example at www.devmoose.com in a post called Automatically Create a Bit.ly URL for WordPress Posts. Just follow the steps in the referred post at devmoose.com to achieve this.  I did a minor modification to the code to make it work in my WordPress : I added “<? php” before the code and  “?>” after the code. I also added the “if function exists” check.

The complete code to add in your functions.php file:

<?php
//create bit.ly url
if ( !function_exists(‘bitly’) ) {
function bitly()
{
//login information
$url = get_permalink(); //generates wordpress’ permalink
$login = ‘yourbitlyusername’; //your bit.ly login
$apikey = ‘yourbitlyapikey’; //bit.ly apikey
$format = ‘json’; //choose between json or xml
$version = ‘2.0.1’;

Continue reading »

Tagged with:
Subscribe to my feeds Follow me on Twitter
DZone MVB