WordPress Digg Shortcode Function – As Seen on WordPress.com

When moving from WordPress.com, my Digg shortcodes broke.

I wanted a simple way to transition my Digg chicklets to a WordPress.org installation.

I created a function that does nothing special, except for reproducing the Digg shortcode functionality on WordPress.com. All you need to do is enter [digg=http://digg.com/path_to_story_on_digg], and it will create a Digg This chicklet for you. Here’s the code in action →

function kwd_digg_shortcode($content = null) {
    $url = $content[0];
    if( substr($url, 0, 1) == '=') { $url = substr($url, 1); };
    $content = '
    <div class="alignright"> <!-- for layout only; you can modify -->
    <script type="text/javascript"> digg_url = "'.$url.'";</script>
    <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
    </div>
';
    return $content;
}
add_shortcode('digg', 'kwd_digg_shortcode');

How to install this on your blog

Simply copy the code above into your theme’s functions.php file. Any existing Digg shortcodes should automatically start working again, and you also will be able to use the functionality as you were doing on the WordPress.com site.

Author: Zack Katz

Zack Katz is the President of Katz Web Services and the developer of WordPress plugins with over 700,000 downloads. He lives in Southwest Colorado with his wife and two cats.

2 thoughts on “WordPress Digg Shortcode Function – As Seen on WordPress.com”

Leave a Reply

Your email address will not be published. Required fields are marked *