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:

digg button
if($digg !== ”) { ?>

<?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:

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

Ashesh

सयौ थुङ्गा फूलका हामी एउटै माला नेपाली, Welcome to my webpage. I'm from the Himalayan Country of Nepal. Well talking about me, I like mostly Web programming and Designing and furthermore I like Philosophical literature, Photography, Social networking. And I am Romantic and Sentimental person to some extent. Read more...

View Comments