Manually Adding Digg Button to WordPress Posts
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!
About this entry
You’re currently reading “Manually Adding Digg Button to WordPress Posts,” an entry on GregAshbaugh.com
- Published:
- 05.05.07 / 6pm
- Category:
- Technology, Word Press
6 Comments
Jump to comment form | comments rss [?] | trackback uri [?]