Creating a Digg Button that actually works in WordPress

Getting the right code to add a Digg Badge that automatically populates the submission information onto my WordPress blog was a challenge, but I managed it! Here’s how I accomplished the task.

It should have been simple thing, I wanted to add a Digg button to my blog to make it easier for my visitors to Digg my posts. I was alarmed to find that none of the code snippets that I could find, including those on the Digg Website seemed to work. After hunting around for awhile I found that the single quotes in the sample code available from Digg was the first piece that need to be corrected. Eventually, through trial and error, I was able to find WordPress template tags that gave me the results that I was looking for.

The code for the Digg badge can be copied from here directly into your WordPress theme templates. Usually in the index.php, single.php, and archive.php. For my own theme I chose to put the code in right after the call for “the_title” You should also note that this code is written specifically to be placed within “the_loop” The code for placing a Digg badge in a sidebar, header or footer, would be different.

The basic code:

[sourcecode language='js']

[/sourcecode] What the code does:

  • This code uses the post’s permalink as the url that is being submitted to Digg.
  • The post’s title and the first 40 words of the post will be pre-filled on the Digg submission screen
  • Optionally, the Digg topic, badge background color, badge type(skin), link target can be set (see below)

On the my front page I wanted a Compact Digg badge. I didn’t like having so many large badges on the front page but I also didn’t want to completely eliminate the badge. All of the preset information can be modified prior to submission by the individual doing the first Digg. I set the code within it’s own div with a class of “diggbadge” so that I can modify the way the badge displays using CSS. The code for a compact badge with the Digg topic of “software” preselected with a link that opens a new window: [sourcecode language='js']
[/sourcecode] The code for a full size badge with the Digg topic of “software” preselected with a link that opens a new window:

[sourcecode language='js']
[/sourcecode]

There are other options that can be added in the code as well:

[sourcecode language='html']
digg_bgcolor = “#ff9900″;
digg_skin = “compact”;
digg_window = “new”;
digg_topic = “software”;
[/sourcecode]

digg_bgcolor sets the background color of the Digg badge. This value will change the background color around the outer edge of the button. If omitted, the default color is white. Any valid CSS color can be entered here.

digg_skin defaults to the full size badge, by setting the value to compact you can have a smaller badge displayed on your site. I like this for pages with multiple posts such as the front page or an archive page. the value of “icon” can also be set which will display a 16X16 icon instead of a badge.

digg_window sets the target of the link. A value of “new” will open a new window when the badge is clicked.

digg_topic sets the topic that the post will be filed under on the Digg site. If you have a consistent topic that your posts fit within this is an additional help for those that might want to Digg your site. The value can be changed from the submission screen by the person Digging your post. The value set here must be one of the topics in the following list:

  • 2008_us_elections
  • apple
  • arts_culture
  • autos
  • baseball
  • basketball
  • business_finance
  • celebrity
  • comedy
  • comics_animation
  • design
  • educational
  • environment
  • extreme_sports
  • food_drink
  • football
  • gadgets
  • gaming_news
  • general_sciences
  • golf
  • hardware
  • health
  • hockey
  • linux_unix
  • microsoft
  • mods
  • motorsport
  • movies
  • music
  • nintendo
  • odd_stuff
  • other_sports
  • pc_games
  • people
  • pets_animals
  • playable_web_games
  • playstation
  • political_opinion
  • politics
  • programming
  • security
  • soccer
  • software
  • space
  • tech_news
  • television
  • tennis
  • travel_places
  • world_news
  • xbox

I hope that this demonstration will be useful! Don’t forget to use the Digg badge up at the top of the post! I’ve done all I can to make it easy for you! For my loyal readers using a feed reader, come on over to the site to see the badges in action. Report any problems with the code snippets back to me!

About Daisy

Comments

  1. The compact size digg button is getting popular these days, and I also prefer that size.

  2. Susan says:

    Congrats :) Glad you got it to work!

    Susans last blog post..Wallpaper

  3. I’d really like to have something that I can place in a particular posting, not in the templates. I don’t think all my postings are Digg-worthy, but some might be and I’d rather have a fantastic compact button/feature like you’ve designed on those individuals pages. Suggestions?

  4. My old Digg button code was scrambling the blog layout. This one works fine. The option of putting additional information like category, title and excerpt is really very helpful.

    Rajeev Edmondss last blog post..Useful Web Tools And Resources For Bloggers: Part – 4

  5. Trisha says:

    I finally got the time to back here and read through this more carefully! I have one question:

    I can’t tell if the title is working with mine – it doesn’t look like it. When I hold my cursor over the digg button, the url that shows in the bottom of the browser just includes the permalink and not the title and not the description I want to use in digg_bodytext either.

    Ruth Marie Sylte – I’m just using mine in specific posts also. Most of mine wouldn’t have a chance in Digg. But for the few that would I want to have something ready for it. My plan is to keep the code for it someplace handy then just copy and paste it into a post when I need it and then fill in the topic and bodytext manually.

    Trishas last blog post..I missed it!

  6. Trisha says:

    Daisy – that closing div that you use at the end of your code seems to get stripped out by WP, at least when it is within a post. Is it necessary?

    This is the code I’m using – for now anyway – if I can get it to post here:

    digg_topic = "fill-in-topic-name-here";
    digg_url = "";
    digg_title = "";
    digg_bodytext = "fill-this-in-with-good-description";

    Trishas last blog post..I missed it!

  7. Trisha says:

    I see some of my code got stripped out of the comment – if anyone is interested, please contact me at my blog to get it.

    And I have another question – Is there a limit to the amount of text that can go into digg_bodytext ?

    Trishas last blog post..I missed it!

  8. Christine says:

    Thanks so much for the great article. After checking an easy half dozen, yours is what got the results I was looking for. Very easy to understand.

Speak Your Mind

*