Categories
Code WordPress

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.

By Zack Katz

Zack Katz is the founder of GravityKit and TrustedLogin. He lives in Leverett, Massachusetts with his wife Juniper.

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

Comments are closed.