Show Tweetmeme Button on Selected WordPress Posts

tweetmeme badge

Tweetmeme is a Digg-like site for popular links on Twitter. Using a Tweetmeme badge can be a helpful reminder for your readers to retweet it – and if my experience is anything to go by, Twitter does send targeted traffic to your blogs. Clicking on the Tweetmeme badge will direct you to your Twitter profile, with a tweet of the format RT @tweetmeme <post title> <post link>.

Integrating Tweetmeme on your blog is as simple as entering some JavaScript code (provided on Tweetmeme website). In this WordPress hack, however, I’ll show you how to display the Tweetmeme button only on posts you decide – by using a custom field. This is crucial, because a Tweetmeme badge on a site announcement would be unprofessional, not to mention redundant.

PHP function to to display Tweetmeme badge

Since you would want to show the Tweetmeme badge on multiple pages (on single.php, index.php etc.), wrapping the code in a simple function is a good idea. We can then call this function wherever we want the badge to be displayed.

Open up your theme’s functions.php file. At the end of the file, you will find a ?>

Place the code below just before that.

function tweetmeme(){
?>
<div style="float: left; margin: 5px 15px 5px 0;">
<script type="text/javascript">
tweetmeme_url = '<?php the_permalink(); ?>';
</script>
<script type="text/javascript" src="https://tweetmeme.com/i/scripts/button.js"></script>
</div>
<?php
}

PHP tag to display the badge

In single.php and index.php, place the code below just before the tag <?php the_content(); ?> or <?php the_excerpt(); ?>.

<?php $check_sm = get_post_meta($post->ID, 'tweetmeme', $single = true);
if($check_sm != '')
tweetmeme();
?>

Enabling the badge on posts

Enabling the Tweetmeme badge requires you to add a custom field to the post in question. On posts where you want to display the post, add a field named tweetmeme with a value true.

You can also extend this hack to hide Tweetmeme badge only on posts where you enter a custom field, or show other badges (Digg, Stumble Upon etc.) selectively.

Guest blogger Sumesh writes Blog Designed, a blog for tips and links on design, SEO and WordPress. You can also follow him on Twitter. If you have some tips to share, write a guest article on QOT.

This is a guest article and represents opinions of the guest author
Share with friends

16
Leave a Reply

avatar
16 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
16 Comment authors
Kang DaniOkenyaCaraPeluangusahabelajar seo Recent comment authors
  Subscribe  
Notify of
hack
hack

Thanks, for useful tip
I will integrate Tweetmeme badge in my website

Jeff Wahdat
Jeff Wahdat

I embedded tweetmeme code into my joomla site, but it will only retweet my entire site and not the specific article. Also, it retweets “RT @tweetmeme…” I want it to “RT @digital_paper….”.

How do I do this?

Zee
Zee

Is there a way to set it to default at “true” and turn it off when required?

Adam Cohen
Adam Cohen

Great idea and suggestions. Have you thought about how to do this with the Thesis WordPress theme? It has custom php functions built in – Not being a developer I’d be interested in guidance on the best way to use a custom field without worrying about theme upgrades. Thanks!

Sarah
Sarah

Hi Jeff

I don’t know if you realized but we do have a joomla addin which you can find details of here:

http://help.tweetmeme.com/2009/04/21/joomla-plugin/

Hopefully it will make your installation easier.

We have a wordpress one for those of you who are on there and instructions for blogger also found here:
http://help.tweetmeme.com/category/addons/plugin/
and here:
http://help.tweetmeme.com/category/addons/button/

I hope it helps you all! :)

Sarah (@talktweetmeme)

Rebecca Geiger
Rebecca Geiger

EEEEEEK! I clearly don’t understand.. I don’t know what to enter in ‘yourname’ .. when I put “my name- @rebeccageiger) it doesn’t work. Am I to put @tweetmeme?
Or true? With quotes? Without quotes? I think I am making this WAY to complicated.
I would really appreciate advice on this one.
weeeeeeeeeeeeeeeeeee!
Rebecca

Rajesh Kanuri @ TechCats
Rajesh Kanuri @ TechCats

How to add Rt@myusername without using plugin in wordpress.. any suggestions pls . . ??

rakesh
rakesh

Finally I got a really nice or we can say useful post. Thanks for sharing a lovely post.

Tech Maish
Tech Maish

Thanks you friend. Now i add tweetme button in my blog.

Chris
Chris

Why would you ever kontera? Do users really want to view a Verizon ad as they are reading your post? Do you at least get a kickback from that?

Ahmad Khoirul Azmee
Ahmad Khoirul Azmee

Thanks a lot, I can hardly find the plugin button on tweetmeme site alone. This is very useful to me as twitter official doesn’t have this tall button.

belajar seo
belajar seo

The article is unique and very loving. Many useful things I learned and use it. There will always be glad to share something new and interesting again on the site.
regards
belajar seo

Peluangusaha
Peluangusaha

now I get what I am searching…it so important because google now consider the effect of socila media

Cara
Cara

nice…Finally I got a really nice or we can say useful post. Thanks for sharing a lovely post.

Okenya
Okenya

How can I got more tweets? Is there any easiest way to get tweet instanly?

Kang Dani
Kang Dani

This I looking for, using script is more simple than plugin. Tweetmeme useful for social signal.