In this post I will show you how to easily create links to the pages on your website whenever you have both a page URL and a page title available. This code automatically removes characters from the end of the title so that in addition to the URL itself and a space character between the maximum length of 140 characters will not be exceeded. If the title is too long it will be truncated and three dots will be added to show that it has been shortened.
When clicking on the link the user is taken to the Twitter homepage with the message already preset so he or she can tweet it immediately with just a single click.
function getTweetUrl($url, $title)
{
$maxTitleLength = 140 – (strlen($url)+1);
if (strlen($title) > $maxTitleLength) {
$title = substr($title, 0, ($maxTitleLength-3)).’…’;
}
$output = “$title $url”;
return ‘http://twitter.com/home?status=’.urlencode($output);
}
?>
Simply add this code to the <head> section of your document in between the <script> tags. Then, in the body of your document, create a link like the one shown below:
<a href=”<?php echo $url; ?>” target=”_blank”><img src=”tweetthis.jpg” border=”0″ alt=”Tweet This!”/></a>
You can replace the image source shown above with your own Twitter button. You now have a “Tweet This” button for your site!
Hello! This is my 1st comment here so I just wanted to give a quick shout out and say I really enjoy reading your posts. Can you recommend any other blogs/websites/forums that cover the same topics? Many thanks!
I am glad you enjoy the posts! http://woorkup.com/category/webdesign/ was very helpful when I was starting out in the web design business, so it may help you as well. Thank you for reading!
You should take part in a contest for among the best blogs on the web. I’ll advocate this site!
Thank you, Elliot! I really appreciate your comment! 🙂
“Hey, thanks for the blog article.Really looking forward to read more. Awesome.”
Thank you! Please check out our facebook page at: https://www.facebook.com/pages/The-webdesignerer-Blog/322090944479607 ! Thank you for your comment and I assure you there is a lot more to come! Very excited about this year!
attention-grabbing point you crafted here – blogesaurus vso software convertxtodvd free download Create a “Tweet This!” Button for your Site webdesignerer
Thank you for the tip, Terrance and thank you for commenting!