Nathaniel Ward

Tuesday Links: Paul Ryan’s Budget


Monday Links: Artificial Scarcity


Creating Clean Amazon Affiliate Links in WordPress

One way bloggers can earn incremental income is through affiliate marketing programs, among which Amazon’s is perhaps the most popular. Bloggers simply link to Amazon products, adding a special referral code, and they are given credit for the sales they generate.

Generating these tracking codes can be something of a pain. Amazon’s own utility is clumsy and offers up a long, clunky URL. Ragaskar’s WordPress plugin aims to fill the void by automatically appending tracking codes to Amazon links in posts, but this can still generate clunky links.

Based on Ragaskar’s plugin, I whipped up the following code:


    add_filter('the_content','filter_amazon_associate_filter');

    add_filter('comment_text','filter_amazon_associate_filter');

    

    function filter_amazon_associate_filter($content) {

        $affiliate_code="YOURCODEHERE";

    

        $content=preg_replace(

            '/http:\/\/[^>]*?amazon.([^\/]*)\/([^>]*?ASIN|gp\/product|exec\/obidos\/tg\/detail\/-|[^>]*?dp)\/([0-9a-zA-Z]{10})[a-zA-Z0-9#\/\*\-\?\&\%\=\,\._;]*/i',

            'http://www.amazon.$1/exec/obidos/ASIN/$3/'.$affiliate_code,

            $content

        );

        return $content;

    }

Very simply, this code scans through your posts and comments and replaces ugly Amazon links with somthing like http://www.amazon.com/exec/obidos/ASIN/B0048EJXCK/nathward-20.

To add this to your site, simply place the above code in your WordPress template’s functions.php file and replace YOURCODEHERE with your Amazon affiliate code.


LinkedIn’s April Fool’s Joke

LinkedIn's 2011 April Fool's Joke

Technology firms have often used April 1 as a chance to play pranks on their customers. Google, for example, is famous for these hoaxes, to the point that its 2004 launch of Gmail (on April 1) was originally viewed as a joke.

In a crowded field of 2011 pranks that includes elaborate videos and even browser extensions, LinkedIn’s prank is perhaps the subtlest and thus the funniest. They added historical figures and fictional characters to their “people you may know” tool, including Albert Einstein, Robin Hood (“Activist/​ Chief Fundraiser at Nottingham”) and J. R. R. Tolkien. Unfortunately, you can’t actually add these people to your network, but it’s a fun gesture nonetheless.

 


Wednesday Links: Unintended Consequences