Wordpress - How do I convert all amazon links to affiliate links?

freezeice04

Power Member
Joined
Jul 5, 2010
Messages
694
Reaction score
299
How do I convert all amazon links to the affiliate link version? Is there a plugin to do this automatically?
 
I am sure there are plugins for that, also not specific to amazon affiliate, i am using a plugin from codecanyon called amazon estore.
 
You have to edit each post manually and generate the affiliate link for each product you are promoting. Then insert them manually.
 
You have to edit each post manually and generate the affiliate link for each product you are promoting. Then insert them manually.
Nonsense..

Add this to functions.php, replace fashionchicks-20 with your affiliate ID.
This way you can easily change the ID later across all your links. I haven't tested it live yet but it should do the job.
Note: this is for posts, and not sidebars etc.
Code:
add_filter('the_content', 'amazon_affiliate');
function amazon_affiliate($url) {
    $affiliate_ID = "fashionchicks-20";
        $url = 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/dp/$3/?tag=".$affiliate_ID,$url );
return $url; 
}
 
Last edited:
Back
Top