Jeremy Knauff

Use Functions.php to Tailor Amazon Affiliate Links

March 18th, 2013 by Jeremy Knauff


If you use Amazon’s affiliate program, and you should, then you’ve noticed that unlike most other affiliate programs, you don’t have many options when it comes to creating your links. Sure, you can edit the code they provide to add additional attributes on your own, but those little bits of work add up fast. I like to add the rel=”nofollow” attribute to my Amazon affiliate links so they aren’t counted by the search engines, and while it is falling out of favor with some standards-obsessed web developers, I still like to add the target=”_blank” attribute for certain links—especially Amazon links. Why? Websites like Amazon tends to suck you in and before you realize it, you have fallen behind on your TPS reports and are late for your meeting with the Bills, and in the ensuing chaos will have forgotten about my site, likely never to return. I want my visitors to stick around as long as possible and come back often, so I need to prevent that.

Manually adding attributes to an existing website is a nightmare task; I know, I’ve done it. But a few lines of PHP in your WordPress functions.php file will automatically add these attributes to your links, both old and new, with no further effort on your part. The snippet of code below is something I created to add the previously mentioned attributes to all of my Amazon links, but you can modify it to add, change, or delete anything your want. Simply paste it before the closing ?> tag in your functions.php file and upload that file to your theme folder.

//Amazon affliate nofollow and blank
//PHP code created by Jeremy Knauff, of Designed by JK

function amazon_nofollow_blank($text) {
$return = str_replace(‘<a href=”’, ‘<a target=”_blank” rel=”nofollow” href=”’, $text);
return $return;
add_filter(‘the_content’, ‘amazon_nofollow_blank’);

Tags: , , , , ,

Leave a Reply

Email Marketing $19/Month!

Recent Work

USA Mobile Drug TestingGeneral Fire EquipmentKey West Home Theater

Copyright 2014 Design by JK, All Rights Reserved. | 5 Reasons You Shouldn't Copy My Stuff.