I recently wrote an article on Search Engine Land and wanted to make sure I posted the code in other places as well in case anyone missed it.
Basically, the code is used to make sure you decide what users tweet.
This is a quick work around that I came up with and my friend Josh (my go-to developer) who helped me put it together.
Simply install this code in the place where you would place a Twitter share button:
<a href=”#” onclick=”tweetSelectedText()”><img src=”http://digitalhighrise.com/wp-content/uploads/2012/05/tweet_button.gif” border=”0″ /></a>
<script type=”text/javascript” src=”http://code.jquery.com/jquery-1.7.2.min.js”></script>
<script type=”text/javascript”>
$().ready(function(){$(‘.tweetThis’).hide();});
function tweetSelectedText(){
var twtTitle = $(‘.tweetThis’).text() || $(‘title’).text();
var twtUrl = location.href;
var maxLength = 140 – (twtUrl.length + 1);
if (twtTitle.length > maxLength) {
twtTitle = twtTitle.substr(0, (maxLength – 3))+’…’;
}
var twtLink = ‘http://twitter.com/home?status=’+encodeURIComponent(twtTitle + ‘ ‘ + twtUrl);
newwindow=window.open(twtLink,’name’,’height=500,width=500′);
if (window.focus) {newwindow.focus()}
}
</script>
Then, in the code of your post (beginning or end, it doesn’t make a difference) add this tag:
<p class= “tweetThis”>THIS IS WHERE YOUR MESSAGE GOES</p>
In this tag, you can craft your own message, which is descriptive, contains the targeted keywords and utilizes the allotted space.
And that’s it. Hope that helps 🙂