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().

Leave a Message

3 Messages

 

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!

 
 

RSS feed for comments on this post. TrackBack URI

Leave a Message