Manually Adding Digg Button to WordPress Posts
5 May 2007Most 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!
|
|
4 Responses to “Manually Adding Digg Button to WordPress Posts”
Leave a Reply
Thanks For Visiting!
May 29th, 2007 at 8:37 am
Nice method, i found your method bt googling..already digg it…
June 15th, 2007 at 2:14 pm
Great! Worked like a charm!
July 14th, 2007 at 12:55 pm
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.
November 24th, 2007 at 3:01 am
Thanks a bunch!