Digg this post with WordPress

It finally works! I just spent nearly an hour just trying to get the “Digg this” link to work properly. I was modeling it after other “Digg this” links on other weblogs, but they all did it different ways. Sometimes it was phase=2, sometimes phase=3. Sometimes the URL was urlencode()’ed, sometimes not. Sometimes they had a title=something, sometimes not. But my link wasn’t working. It kept taking me to the Digg login page instead of the “Submit Story” page. I was nearly pulling my hair out, until I analyzed a working and a non-working link closely, character-by-character. The culprit?

www. was missing in the working link.

That’s right. If I had http://www.digg.com/submit?…, it did not work. But if I used http://digg.com/submit?…, it did. URL did not need to be encoded. phase didn’t matter. title didn’t matter. The key is that digg.com is now just digg.com without the www., and if you use the www along with the submit stuff, it will redirect to their login page. Problem solved.

Another thing I looked at is WordPress’s “the_permalink()” function. It’s weird. It actually prints the permalink, and doesn’t return it. So all of this code does not behave as expected, as far as I can tell:

< ?php urlencode( the_permalink() ); ?>

< ?php stripslashes( the_title() ); ?>

The urlencode() and stripslashes() functions here do nothing, as far as I can tell. Whether they are there or not, the output is the same! Luckily, you can work with the permalink like this:

< ?php echo urlencode( get_permalink() ); ?>

If you wish (I ended up not needing this for the Digg this code). Make sure you echo (emphasis mine – don’t include it in your code, of course)! get_permalink actually does return the permalink, so you have to echo it in order to see anything.

This oddity is what caused me to think urlencode() wasn’t working right, when it actually was. So there’s no need to convert / to %2F in PHP. It can be taken care of with urlencode(), and there’s no need to bother with str_replace().

7 Responses to “Digg this post with WordPress”

  1. […] Summer « Digg this post with WordPress […]

  2. I’ve been looking around for the solution to this problem forever! I wasn’t aware that the_title() was printing by default and not returning the value (of course my level of PHP knowledge can explain this oversight too ;-)) Anyway, now my post to del.icio.us button works like a charm. Thanks man!

  3. Peter says:

    I too was spending much time and experiencing much frustration. Thanks for your post! However, many people after reading it will still want to urlencode the_title() and run up against the same problem. The solution is:

    Thanks again!

  4. Acomplia says:

    Acomplia (rimonabant) is an anti-obesity drug. It was approved for marketing in the European Union in June 2006. Rimonabant is not yet approved for use in the United States, where it is known as Zimulti. http://www.acompliaonline.com

  5. Breast enlargement products that gives you fuller, firmer, larger, rounder perfect cup size breast in few weeks which increase the beauty of your body and gives you full confidence! http://www.big-breast-enlargement.com

  6. Best penis enlargement – VigRx Plus (Best Penis Enlargement Pills), Devices, Really working Can increase the growth of the penis up to 4-7 inches, without side effects, 100% Money Back Guarantee

    http://www.orderpenisenlargement.com

Leave a Reply