Tweet This Post Without The Plugin

I’ve received quite a few emails asking how I modified the Tweet This WordPress plugin to make it performed the way that I wanted. I was going to write a little tutorial on it but then @Marhgil over at Macuha.com informed me that I could have created the Tweet This link without a plugin.

Because I only wanted to insert the Tweet This link at the bottom of my posts and didn’t needed any of the other features the Tweet This plugin offered, it would just be a simple matter of adding one line of code to the single.php file. Marhgil explained how he did it here. I made a couple changes to clean up the codes a little.

<a rel=”nofollow” href=”http://twitter.com/home/?status=Reading @JohnChow – <?php the_title(); ?> http://johnchow.com/?p=<?php the_ID(); ?>”><img src=”http://www.johnchow.com/images/tweet-this.png” alt=”Tweet This” /> <strong>Tweet This Post!</strong></a>

Insert the above code (change to your domain and twitter name) to your WordPress single.php file at the point where you want the Tweet This link to show up. In my case, I have it appear right after the post.

You will noticed that the link uses the default WordPress URL structure of http://johnchow.com/?p=xxxx instead of the SEO friendly URL. Doing it this way will allow you to bypass the use of an URL shorten service. JohnChow.com only has one more letter than TinyURL.com so this isn’t a big deal. What is a big deal is the URL has my domain name in it and reinforces my brand. You can save yourself a few letters by using www instead of http:// as Twitter.com will auto link the URL. However, Twitter clients like TweetDeck will not link the URL if it’s missing the http:// so I recommend you stick with it.

You won’t have to worry about readers getting to your blog using the default URL because WordPress will auto forward them to the SEO friendly URL. I added a ref=nofollow tag to ensure that no Google juice is passed to the short URL.

The advantage of using a line of code instead of a plugin is less overhead. A simple line of code consume less resources than an entire WordPress plugin so your blog should run faster. The other advantage is using your own domain in the short URL to help reinforce your brand.


62 thoughts on “Tweet This Post Without The Plugin”

  1. haa cant believe they had a plugin for such a simple line of code – well its less stress on wordpress backend I guess

    1. Thanks for this. Got the code installed, up and running already!

      1. Your personal brand is so important when working on Twitter. So many people are clicking through thousands of links per day on Twitter, most being shortened URL’s that they easily forget where they’ve been after just a few hours.

        Great tip John!

    2. Tweet This is now 463 lines of code. That means it’s 463 times better, right? :-p

      Anyway, the plugin is preferable if you want to use TinyURL or other services because it caches URLs instead of constantly hitting the external server, and it lets you change the text, URL services, and display options without touching your theme.

      1. You are right and I think it less messy if you forget anything in the lines of code.

  2. Steitiyeh says:

    Thanks John for sharing, i was facing couple of problems with the plugin itself and i deleted it an hour ago!

  3. I really like the idea of using a code snippet instead of a plugin. Its cleaner and easier to manage.

    It is a clever idea to use your own short blog url rather than using a URL from a another service.

    Thanks for sharing this tip.

  4. Thanks for othe useful tutorial! I’m sure all the twitter users will be able to make good use out of this!!

  5. Ryan says:

    Thanks John for the great tip. If I needed to use a URL shortener, where could I find info on doing it?

    Thanks,
    Ryan.

  6. This is just perfect! Thanks for sharing, John.

    1. Cooking School -whats that YAN

  7. Reyn Aria says:

    Why didn’t I think about that before… That’s clever. Thanks John.

  8. Great little tutorial for people not used to coding!

    1. Sometimes I get problems with coding and like to use plugins, but it is great to have another way to do it if anything else fails.

  9. Thanks for the this nice piece of code.

  10. Your blog is without a doubt one of the most informative and helpful blogs out there. I truly appreciate your content. I am always trying to look to improve my knowledge and strategy to make my own business stronger. I am never disappointed when I come here. Thank You and Keep up the good work

      1. Hey Zubin – I can see a lot of Tweaking of WP on your site these days. it seems you are lovin it.

    1. Agreed. I like that he gives you info straight up with no BS.

  11. game-girl says:

    Greatnees is always simple.Good idea to apply it widely.

  12. Thanks for this, i’ll try it today :)

  13. marhgil says:

    thanks for featuring the code! i overlooked putting the nofollow tag, i’m adding it on my code now. now, i’m preparing my blog for a John Chow effect. :) thanks for the link!

    1. You must get ready for this – It would be your Lucky day today Marhgil. See the visitor graph popping sky high.

    2. Glenn says:

      congrats marghil, nice wordpress code :)

      1. Wow, I hope one of my posts will also be linked by John Chow. Congratulations Marghil! Definitely that would mean more earnings for you. :)

    3. ah..preparing the blog….increasing your server resources temporarily ey! πŸ˜€

    4. RTFVerterra says:

      Marhgil, you’re the man

      RTFVerterra’s last blog post: How Free Kaspersky Antivirus with Serial Saved Me

  14. Dan says:

    I saw the @Marhgil tutorial and added it to one of my blogs.

    I did add a hashtag to mine, had to use %23 for the # sign or else it was dropped by twitter.

  15. reflux says:

    I am not yet join the twitter…..I think, above is great information, thanks john

  16. gladys_cute says:

    Can I add this in my photo-gallery-based blog? I want to share my sexy pics for all over the world. Can I?

  17. SEO Tips says:

    Thats excellent I shall be trying that out soon. Looks much cleaner.

  18. Ill shall wait for social bookmarking sites to add this to their options.

  19. Ruben Ricart says:

    I was wondering about the same thing but did not ask the question – thanks for sharing…

  20. 100wordrants says:

    Simplicity at its finest! Thanks John!

  21. This is really useful for me. Thanks for sharing the code. I’d love to know how to code.

  22. Eligio says:

    nice little line of code, this can be also use in any website that need to be broadcast in twitter. thanks for sharing πŸ˜€

  23. Andrew says:

    Any ideas on how to add a tweet this button to the homepage of a html site while keeping the shorturl feature? I’ve been looking everywhere for this and haven’t been able to find anything. Thanks for any help.

  24. Interesting, thanks for sharing this, John.

  25. game-girl says:

    Nowhere else I could find such easy and interesting ideas.

  26. Will Lowrey says:

    For those out there using the Thesis theme, here is a way of adding the same thing without editing the core files in the template.

    function custom_tweet_this() {
    ?>
    <a rel=”nofollow” href=”http://twitter.com/home/?status=Reading @WillLowrey – http://online-profit-center.com/?p=“> Tweet This Post!

    <?php
    }

    add_action(thesis_hook_after_post, custom_tweet_this);

    Add it to your custom_functions.php and you are good to go.

  27. Reyn Aria says:

    I managed to make some adjustments so that the bird pic is a bit transparent and will fully visible upon hovering. No need to install the plugin as well. You need to take the pic from the Twit This plugin though.

    Put this in style.css file:

    .tt-big{
    background:url(images/tweet-this.png) no-repeat 0px 0px;
    height: 60px;
    width: 60px;
    padding:0px;
    margin:0px 0px 0px 0px;
    }

    .tt-big:hover{
    background:url(images/tweet-this.png) no-repeat 0px -60px;
    height: 60px;
    width: 60px;
    padding:0px;
    margin:0px 0px 0px 0px;
    }

    Put this anywhere inside the single.php file:

    <a rel=”nofollow” target=”blank” href=”http://twitter.com/home/?status=Reading @Reyn Aria – http://MyNetworkMarketingBlog.com/?p=” title=”Post to Twitter ()”>

    Change as necessary…

  28. shun2u says:

    Thanks. Will insert the code. :)

  29. wow! marhgil’s twit this code was indeed featured here! yay!

  30. I see John uses Tweets on his blog but I am a bit hesitant as it will clutter up the site. Do you really gain anything?

  31. Marvelous! It took some work but it’s working! Thank you.

  32. diabetes man says:

    thanks for good news john……

  33. Yep, this is the kind of code I have going on one of my sites. The only difference is I don’t have the big bird next to it, just the small “t” icon. Either way, the code works out way better than the plugin.

  34. qarla says:

    Macuha rules!

  35. peter

    says:

    hey i would love to get this thing to work but for some reason it displays one of my blog urls and then a weird question mark symbol then the twitter url, when i click it it just loads some other post on my blog… any ideas? thanks.

    1. Steve says:

      I’ve got the EXACT SAME ISSUE! Can someone provide any ideas?

  36. Such a great help for me personally. I really looking for this kind of tutorial coz I have problem in getting sufficient traffic for my site. This can be handy though.

    The best thing about it is it will let our blog run faster as compared if we used common widget/plugin. This will definitely will solve my slow-loading blog (n_n)

  37. jsonvega says:

    thanks! it works great! rock on!

  38. Lucia says:

    Love this! How can I do this using Blogger?

  39. I learned it from another blog and I installed it on my blog but with a different image. I’m just thinking if I should change the image to the bird pic.

    Peter Lee

  40. Gagan says:

    all i can is THANKS

  41. Steven Lewis says:

    I enjoyed this article because I recently started using the “Tweet This” plugin on my blogs. It does come packed with a whole lot of stuff that most people won’t even use… but I suppose it’s better to have “more” than not enough, you know. πŸ˜‰ Thanks for the info… it’s going to come in handy for customizing my future blogs.

Comments are closed.