Share on Twitter link

Twitter bird

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>

77 Responses

  1. Thang

    That’s great!

  2. 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

  3. 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

  4. 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!

  5. Genner Puello

    This was just the answer what i was looking for. Thanks Jamie, you’re a legend!

  6. Simona

    Thank you!! Finally I found a site with a code that does what I’m looking for and it owrks!!
    Great!!

  7. 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.

  8. Amer Schap

    Thanks for the great sample. It took me some time to find this.

  9. Ty Dubcomm

    awesome! thanks!

    now, what about the same functionality for Facebook?!

  10. Karen Wirsig

    I am guest-hosting a blog this week and just added the code, with slight modification, and it works great. Thanks!

  11. 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

  12. Pete

    Code works…but you need to change the quotation marks! Thanks

  13. Jamie Huskisson

    The quotation marks look fine Pete. What is it you’re seeing wrong with them?

  14. Andreas

    Excellent – I was looking all nite for a solution like that. You made my day!

  15. Pingback on

    Cómo crear un enlace para enviar a twitter [Enlace] | Libro de Apuntes

  16. room34

    Short and sweet. Thanks!

  17. 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 with rawurlencode('Currently reading ' . trackback_url(false)) and let PHP handle that.

  18. 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 :)

  19. Megan502

    does this string work for e-mail as well? I need to add a “share this on twitter” to a marketing email

  20. 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.

  21. Jason

    Thanks. I looked around and could not easily find this anywhere else.

  22. Perr

    It works for me ~ Thank you so much!

  23. Tracey

    Very helpful. Exactly what I was looking for and worked right away.
    Whew! Thanks!

  24. 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

  25. Andrew

    when I have a link with # it doesn’t post anything after the #. How does one get around this?

  26. Maragues

    Beware using url special characters such as ‘%’, it wonk work unless you encode it.

    Using urlencode(‘50%’) will do the work in php.

  27. Johannes Leuchovius

    Thanks :)

  28. 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>

  29. Pingback on

  30. rabbit

    Hi, Where can i get the small twitter icon to put in this link in an tag?
    thanks in advance!

  31. caksyam

    Thanks for sharing! This is an awesome post.

  32. catch_down (catch_down)

    http://tinyurl.com/ddwvfe
    ‘Share on Twitter’ link : Jamie Huskisson Blog

  33. Bob

    How do I pass special characters like ?, , !, and & ????

    Thank you!!!

  34. Os

    Thank you so much for this code; i like the straight-forward implementation and explanation.

  35. senn

    Thanks for the solution, just what I’m looking for. :)

  36. keither

    Thanks so much your post :)

  37. Petzume

    Thanks, this is great. I did have to change the quotation marks, but besides that it works.

  38. PERANTARA (PERANTARADOTNET)

  39. Sarah Lewis

    Thanks for the tip. It’s simple, but I can never remember the syntax right off the top of my head. :)

  40. 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.

  41. Tushar Mahajan

    Thank’s A Lot
    It Really Helpfull

  42. @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

  43. @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

  44. Jimmy Corn

    Wicked, worked straight away! ACE STUFF

  45. Noel

    Thanks so much, adding to our blog now.

  46. FranRood (Francesca Rood)

    @emmybabee yea that did not work i dunna this says how to thoughhttp://jhuskisson.com/code-tidbits/share-on-twitter-link

  47. TheCosmonaut

    Thanks much – worked like a charm!

  48. siraj

    Thanks bro :D

  49. Laurie Buchanan

    thank you, Thank You, THANK YOU!

  50. Jennie

    So simple and so helpful! Thanks very much :)

  51. Pino

    Thanks, very very much. Short and complete.

  52. Mike Fisher

    what about the URL-shortener? how can I plug this into the link?

  53. Lois

    Other sites make this seem complicated. Thank you for the straightforward solution!

  54. Pingback on

  55. Pingback on

  56. da_wacintosh (wac)

  57. reece

    can you add this code into magento?

  58. 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

  59. matthnews (Matt H)

    Want to add a shair this on #Twitter or #facebook to your website? Here is how. http://tinyurl.com/ddwvfe

  60. Pingback on

    10 Essential Social Media Tips for Ecommerce Sites « {zb}Interactive's Lead Feed

  61. Pingback on

  62. Pingback on

  63. 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?

  64. luckystar

    Hi, there is one issue that if I haven’t login yet, twitter will redirect to homepage with no status.
    Share on Twitter

  65. Pingback on

    10 Essential Social Media Tips for Ecommerce Sites | Retail Marketing Strategy

  66. Pingback on

  67. 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.

  68. 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?

    1. Tunner

      Use Friendly-URL’s.

  69. Egzon

    How about joomla?

  70. Dennis Terrey

    Is there a way to redirect to my site once someone has click the “tweet share” link from my site?

  71. gaweb

    Hi,
    Did you get an answer for the shortening of the url ?
    Thanks a lot !
    Gaweb

  72. moncler

    Hi. Thanks for the tips!

    I’m having problems passing a URL with the character “&”. i.e.

  73. Pingback on

  74. 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.

  75. 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!

  76. 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, …

Comments are closed, but feel free to @jhuskisson on Twitter with your thoughts.