Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Add a Digg Button in your WordPress using Custom Fields

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Add a Digg Button in your WordPress using Custom Fields

You will see that many sites add a digg button within their post content. Some new users simply open single.php and add the digg script which will cause a digg button to show on all blog posts. But what if you want to display digg button on only specific posts? You can add it manually on each post when writing a post, but that is not the most efficient way. In this article we will show you, how you can add a digg button on specific posts by simply using Custom fields.

First open your single.php and find a code that looks like this:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Replace it with:

<?php if (have_posts()) : while (have_posts()) : the_post();
// check for digg button for single page
$digg = get_post_meta($post->ID, 'Digg', $single = true);

Now you need to add the following code within the loop anywhere you like:

<?php // if there's a single page digg button
if($digg !== '') { ?>
<script src="" type="text/javascript"></script>
<?php } // end if statement
// if there's not a digg button
else { echo ''; } ?>

You may wrap it around with any styling that you want. Save the single.php and upload it to your theme folder.

Now when writing a post if you want to add a digg post simply add a custom field like shown in the screen shot below:

Add a Digg Button in Your WordPress using Custom Field

Whenever you specify this custom field, WordPress will display a digg button on your post like this one:

Check out this example (Live)

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Darren Nickerson says:

    There are also numerous plugins for this, that what I use on my sites. This way seems pretty good if you didn’t want it on every post. Thanks

    • Editorial Staff says:

      Yes, but the more plugin you run, the more vulnerable your site is. It is preferred to get as many things hard coded as possible, so you don’t put too much load on your server.

  2. Jake Rocheleau says:

    Pretty nice tutorial, I actually have this set up on my blog and it’s pretty easy to get going on WordPress. I have it set up on a few popular posts, such as my latest one:

    Link Removed due to the Violation of our Comment Policy

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.