Quick Twitter DIY – How to Make a ReTweetThis button for your WordPress Blog from Scratch!

Well, I’ve been messing with Twitter today, I even made a new URL shortening called U2S.Me in 2 hours, here’s how to make ReTweet This! button for your WordPress blog froms scratch:

For those of you who want to create your own “ReTweet This!” button using your favorite URL shortener, (mine is U2S.Me, which I made from scratch) you can easily implement a CURL into your single.php to make this happen on the fly.

Here’s how to do it, add the following code in your single.php (This example uses U2S.Me to shorten URLs, you can easily change the 1st line of the PHP to fit TinyURL API or any other URL shortener you like but yes, do feel free to use mine, as it’s free!)

*Place the code where you want your ReTweet This! button to appear, I’ve placed before my content so Twitters can see it if they come to my site.

<div class=”retweet snap_noshot”>
<?php
$newurl=exec(’curl “http://u2s.me/api.php?url=’.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’].’”‘);
$ttitle = get_the_title();
if(strlen($ttitle>110)) {
$ttitle = substr($ttitle, 0,110);
$ttitle .=’…’;
}
$ttitle .=’ ‘;
$turl = ‘http://twitter.com/home?status=’.$ttitle.$newurl;
echo ‘<a target=”_blank” href=”‘.$turl.’”>ReTweet This!</a>’;
?>
</div>

Now, this will basically execute CURL command to get the shortened URL back from U2S.Me, a URL shortening I made couple hours earlier in about couple hours.

You’ve probably noticed other codes that do something like http://myblog.com/p?=112 and this isn’t really great for SEO, shortening your URL first through a URL shortening service lets you preserve your SEO-friendly URL such as http://myblog.com/mycategory/myblogpost.

Here’s a sample Tweet created from the code:

The nuclear doorbell http://u2s.me/vkb1

zedomax

Above is the button generated on Zedomax.com, now you can easily do this too by adding the CSS like this in your style.css file:
.retweet {
float:right;
height:30px;
width:110px;
text-align:center;
margin: 0 0 10px 10px;
padding: 5px 0 0 0;
border:1px solid #0018ff;
background: #0018ff;
-moz-border-radius: 5px;
-khtml-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.retweet a {
color:#fff;
text-decoration:none;
}

via twitter hacking blog

Leave a Reply

Your email address will not be published.


Check out more interesting categories: Blog, Computer, Consumer, DIY, Educational, Entertainment, Featured DIYs, Hack, HOWTO, Misc, Projects, Twitter, Wordpress.


Related News and Resources