WordPress Digg Shortcode Function – As Seen on WordPress.com

July 23, 2009

in Code, WordPress

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.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Twitter

Related posts:

  1. Get Adjacent Images – More WordPress Functions
  2. Save Coding Time by Creating Special-Case Categories in WordPress
  3. Nofollow SEO for your WordPress Functions
  4. Auto-Optimize WordPress Database without a Plugin

{ 2 comments… read them below or add one }

nemokami skelbimai July 24, 2009 at 3:22 am

great and helpful stuff

Reply

Freelance Jobs July 25, 2009 at 12:02 am

I will tested on my blog. Thanks for share this shortcode ;)

Reply

Leave a Comment

Previous post:

Next post: