How to make a ‘share this post on Twitter’ link in WordPress

This tips applies to coding a WordPress theme design. You won’t be able to copy and paste the code straight into your posts. You will need full access to editing themes on your server (yes, I can host WordPress sites if you contact me).

Should produce valid HTML and work nicely, mostly the work of Jamie Huskisson and Herself’s Webtools. I added a quick change to produce completely valid HTML (I’m very fussy about that sort of thing).

<a href=”http://twitter.com/home?status=I+like+<?php echo urlencode(get_permalink(get_the_ID())); ?>&amp;title=<?php echo urlencode(get_the_title(get_the_ID())); ?>”> Share this on Twitter </a>

UPDATE: Twitter has changed it’s url format. This is the new format:

http://twitter.com/intent/tweet?text=I+like+http%3A%2F%2Fwww.jameswilkesdesign.co.uk%2Fwordpress-plugin-to-share-posts%2F&title=WordPress+plugin+to+share+posts+via+facebook%2C+twitter+etc

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter

Leave a Comment