Ever wanted to give your readers, or your client’s readers a chance to share the post quickly on Twitter?
The code is straight forward:
<a href=”http://twitter.com/home?status=Currently reading ” title=”Click to share this post on Twitter”>Share on Twitter</a>
If you’re using WordPress and want to automate this, simply use the following to insert the link to the current post in the loop into your link:
<a href=”http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>” title=”Click to share this post on Twitter”>Share on Twitter</a>
Thang —
That’s great!
Clint —
I’m trying to manually add the social networking sites that we want to my company site and I’m not having any luck with your Twitter code.
I’ve tried using a URL encoder for the href because I thought the spaces were the problem, but still no luck.
Does this code still work?
Many thanks,
Clint
Mohammed —
Thanks Jamie,
I was looking to do this for a client and spend some time chasing the link till i got your good example.
?status= was the key.
Thank you
Pange —
@Clint: I think the problem is because of the quotation marks. Change the fancyquotes to simple keyboard “s and the code works fine. Huzzah!
Genner Puello —
This was just the answer what i was looking for. Thanks Jamie, you’re a legend!
Simona —
Thank you!! Finally I found a site with a code that does what I’m looking for and it owrks!!
Great!!
Steven —
Thank you!! It’s a pain tracking down all the different variations of code for the plethora of social bookmark sites.
Btw–nice uber clean site Jamie.
Amer Schap —
Thanks for the great sample. It took me some time to find this.
Ty Dubcomm —
awesome! thanks!
now, what about the same functionality for Facebook?!
Karen Wirsig —
I am guest-hosting a blog this week and just added the code, with slight modification, and it works great. Thanks!
st3fan —
What about url enconding? Would Twitter decode it if I decide to URL encoded it?
If I´d like to post a link or plain text containing “?” and “&” for example.
Ty Dubcomm, you can find more info about sharing links on Facebook here; http://www.facebook.com/share_partners.php
Pete —
Code works…but you need to change the quotation marks! Thanks
Jamie Huskisson —
The quotation marks look fine Pete. What is it you’re seeing wrong with them?
Andreas —
Excellent – I was looking all nite for a solution like that. You made my day!
Pingback on
Cómo crear un enlace para enviar a twitter [Enlace] | Libro de Apuntes
room34 —
Short and sweet. Thanks!
room34 —
A couple more things I just thought of as I was implementing this (less short and sweet, unfortunately):
Regarding the problem of quotation marks, as Pange noted — WordPress automatically turns regular quotation marks in a post into smart quotes, and that’s what’s happening here. If someone (i.e. me) copies the code from your post above, they’ll need to change the smart quotes into straight quotes in their text editor before using the code.
The other thing is the link itself, in the WordPress sample. You certainly can use
the_permalink()
but if your URLs have query strings in them, things can get messy. In my own little snippet of “share this” code (that I have been meaning to turn into a full-fledged WordPress plugin), I have taken to using the following instead:echo rawurlencode(trackback_url(false))
I haven’t really investigated the difference between trackback URLs and permalinks in WordPress — maybe they’re the same. But I like getting trackbacks when people link to my content. The important thing here though is the
rawurlencode()
function — it’ll handle the query-string-within-a-query-string problem.And finally (since I can’t seem to shut up), it is probably a good idea to put
%20
in place of the spaces in “Currently reading” in the URL. Alternately, you could just go withrawurlencode('Currently reading ' . trackback_url(false))
and let PHP handle that.Jamie Huskisson —
Thanks for the feedback room34. I’ll likely take a look at this post and re-organise it to work in a solution that bares in mind query strings in the URLs and the like :)
Megan502 —
does this string work for e-mail as well? I need to add a “share this on twitter” to a marketing email
Jamie Huskisson —
Megan502 – it certainly does. Just make sure to copy and paste it into your browser first to check that it works before putting inside your e-mail as a link.
Jason —
Thanks. I looked around and could not easily find this anywhere else.
Perr —
It works for me ~ Thank you so much!
Tracey —
Very helpful. Exactly what I was looking for and worked right away.
Whew! Thanks!
susanna —
Hi, I might be an idiot, but I don’t know what this means: …. insert the link to the current post in the loop into your link… :-/ I am sorry.
When I add the code to wordpress it just shows up as code…this is what shows up on the post:
” title=”Click to share this post on Twitter”>Share on Twitter
Anyone a suggestion?
thanks Susanna
Andrew —
when I have a link with # it doesn’t post anything after the #. How does one get around this?
Maragues —
Beware using url special characters such as ‘%’, it wonk work unless you encode it.
Using urlencode(‘50%’) will do the work in php.
Johannes Leuchovius —
Thanks :)
Diana —
Thank you so much! This is just what I was looking for. Here’s a small modification I made to the code to make sure it opens in a new window:
<a href="http://twitter.com/home?status=I'm reading" title="Talk about it on Twitter" target="_blank">Share this on Twitter</a>
Pingback on
eTc :: El blog de Marketing en Español » Blog Archive » Pinceladas sociales: ¿Cómo adaptar tu site a la web social?
rabbit —
Hi, Where can i get the small twitter icon to put in this link in an tag?
thanks in advance!
caksyam —
Thanks for sharing! This is an awesome post.
catch_down (catch_down) —
http://tinyurl.com/ddwvfe
‘Share on Twitter’ link : Jamie Huskisson Blog
Bob —
How do I pass special characters like ?, , !, and & ????
Thank you!!!
Os —
Thank you so much for this code; i like the straight-forward implementation and explanation.
senn —
Thanks for the solution, just what I’m looking for. :)
keither —
Thanks so much your post :)
Petzume —
Thanks, this is great. I did have to change the quotation marks, but besides that it works.
PERANTARA (PERANTARADOTNET) —
how to share a page on twitter … http://jhuskisson.com/code-tidbits/share-on-twitter-link
Sarah Lewis —
Thanks for the tip. It’s simple, but I can never remember the syntax right off the top of my head. :)
flakey —
Your link contains syntax errors. I mean, you are supposed to encode URLs when you use them as parameters within a URL, and also spaces. The correct url for your link would be:
Currently+reading+http%3a%2f%2fwww.test.com%2fpost-url
It’s pretty picky of me but using a title attribute for a link is debatable. I can READ the link text, I don’t need a nagging title when I hover my mouse over it.
Tushar Mahajan —
Thank’s A Lot
It Really Helpfull
@Up_in_Smoke —
I also changed the quotation marks only , from what was proffered to the standard quotation marks on my Mac,,,,and it suddenly started working…Should point out that I use Blogger…..Thanks…Mark
@Up_in_Smoke —
And Thanks Diana…I saw your post on the simple MOD to make this open in a new window…Worked perfectly…and you already changed the Quotation Marks…Brilliant
Share this on Twitter
Still only using this on Blogger…pasted into body section after section…expand widget code must be expanded
Jimmy Corn —
Wicked, worked straight away! ACE STUFF
Noel —
Thanks so much, adding to our blog now.
FranRood (Francesca Rood) —
@emmybabee yea that did not work i dunna this says how to thoughhttp://jhuskisson.com/code-tidbits/share-on-twitter-link
TheCosmonaut —
Thanks much – worked like a charm!
siraj —
Thanks bro :D
Laurie Buchanan —
thank you, Thank You, THANK YOU!
Jennie —
So simple and so helpful! Thanks very much :)
Pino —
Thanks, very very much. Short and complete.
Mike Fisher —
what about the URL-shortener? how can I plug this into the link?
Lois —
Other sites make this seem complicated. Thank you for the straightforward solution!
Pingback on
How to add a ‘Twitter this’ link in Wordpress theme « Jameswilkes's Blog
Pingback on
Code to Create Custom Share Buttons for Facebook, Twitter, LinkedIn and Delicious « A DotNet Intellectualism
da_wacintosh (wac) —
http://jhuskisson.com/code-tidbits/share-on-twitter-link
reece —
can you add this code into magento?
masoud —
Hi everybody
I’ve used this code in smarty templates and I have some problems in url encoding for “%” character. for example when the currently reading contain this character like “75% OFF”. How can i encode urls in smarty templates? I guess I have do it using php, but i really have no idea how to do that.
any suggestion???
Thank you
matthnews (Matt H) —
Want to add a shair this on #Twitter or #facebook to your website? Here is how. http://tinyurl.com/ddwvfe
Pingback on
10 Essential Social Media Tips for Ecommerce Sites « {zb}Interactive's Lead Feed
Pingback on
Code : Share Community « Jiwako's Blog
Pingback on
10 Essential Social Media Tips for Ecommerce Sites | Review Crushers
Gift vincy —
This post is very much helpful. Thank you.
But, Instead of redirecting to twitter home and submit, I need, the status should be automatically updated. Can you please give any Idea?
luckystar —
Hi, there is one issue that if I haven’t login yet, twitter will redirect to homepage with no status.
Share on Twitter
Pingback on
10 Essential Social Media Tips for Ecommerce Sites | Retail Marketing Strategy
Pingback on
How to insert social share buttons [facebook, twitter, buzz, digg] – rushlay
lindsey —
I would like to know … is there any way to shorten the URL as well using this method. A lot of our URL page is long.
Brenden —
Hi. Thanks for the tips!
I’m having problems passing a URL with the character “&”. i.e.
?status=Checkout+http://www.mysite.com/home?page=show_ad&adid=13
Twitter ignores anything after & so only passes:
Checkout
Any suggestions?
Tunner —
Use Friendly-URL’s.
Egzon —
How about joomla?
Dennis Terrey —
Is there a way to redirect to my site once someone has click the “tweet share” link from my site?
gaweb —
Hi,
Did you get an answer for the shortening of the url ?
Thanks a lot !
Gaweb
moncler —
Hi. Thanks for the tips!
I’m having problems passing a URL with the character “&”. i.e.
Pingback on
Share on Twitter link : Blog : Jamie Huskisson « 水清浅
Deepak —
Can any one tell me how to do it on mobile browser.
I tried doing it with – http://mobile.twitter.com/home?status=I would be happy if this gets posted . It didn’t work for me :(.
Would be really thankful if anyone of you can help me on this.
Alecia @ Savings & Stewardship —
That’s great, but how do we get our Twitter Share Button to generate the same type of tweet that yours does? Instead of saying “Reading This – url”, to say “Title of Post – url via @…”? Thanks!
Ludovic —
Exactly what I needed: a simple and clean solution (just a “pure” HTML link). I am kind of tired of all those javascript based buttons like Twitter’s, Facebook’s, … that are hard to align, have different sizes sometimes, …