Manually Adding Digg Button to WordPress Posts

5 May 2007

Most people that use WordPress use some type of plugin to add social bookmarking buttons / links into their posts.

I wasn’t interesting in having that on every post, but recently I wanted to put a Digg button on one of my posts. Because I only wanted to use it on one single post, that means I had to embed the code in that particular post.

Lastly, I only wanted the Digg button to show on it’s own page, which is the part of this post which is unique to WordPress.

Here is how I did it.

This is the following code to add your post to get the button. You will need to put the Digg URL of your post here. This either means you have to Digg your article once to get the link, or wait till someone Diggs it.

<script type="text/javascript">
digg_url = "Dig Post Here";
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript">
</script>

This is the portion to make the button only display on it’s own page, known as single.php in WordPress:

First you need a plugin that will allow you to embed PHP code into your posts, so it doesn’t get treated as text. I already had one installed so this wasn’t an issue.

The plugin I use for PHP is Exec-PHP. The reason I like this plugin is because I can enter PHP with the traditional tags whereas some other similar plugins make you wrap your PHP code with different methods.

You will need to wrap the code we made earlier, with the following tags

<?php if( is_single() ) { ?>
<?php } ?> 

The final result will look like such:

<?php if( is_single() ) { ?>
<script type="text/javascript">
digg_url = "http://digg.com/yourURL";
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript">
</script>
<?php } ?>

That’s all there is to it!


5 Responses to “Manually Adding Digg Button to WordPress Posts”

  1. iCalvyn Says:

    Nice method, i found your method bt googling..already digg it…

  2. Matt Jones Says:

    Great! Worked like a charm!

  3. Colin Says:

    Thanks so much for this! I was pulling my hair trying to figure out how to get the digg button to show only on the post and not on the homepage.

  4. steve3279 Says:

    Thanks a bunch!

  5. Adam Says:

    Thanks! Finally had a story go popular on Digg today and this page was a big help.

    Cheers,
    Adam

Leave a Reply

Thanks For Visiting!