How to Redirect Affiliate Links to Your Ebates Referral Link

SAH Affiliate

Many of you are upset about's decision to close the Very Important Blogger affiliate program. Or, maybe the recent events that have occurred have made you question the integrity of ShopAtHome.

If you've decided not to promote the cash back company anymore, what do you do with the affiliate links already on your site? Don't give ShopAtHome those anchor links! Instead, redirect the existing links to another cash back site, like Ebates.

To accomplish this, simply insert the following code into your theme's functions.php file (or custom_functions.php). Make sure to replace YOUR LINK with your Ebates referral link.

If you're using the Thesis theme for WordPress, select the Custom File Editor under the Thesis menu. Change the file you're editing to custom_functions.php, then paste the following code at the bottom of the file, before the ?> (if there is one).

function replacesah($text) {
	$return = str_replace('href="', 'href="YOUR EBATES LINK"', $text);
	$return = str_replace('href="', 'href="YOUR EBATES LINK', $return);
	$return = str_replace('target = "_blank" href = "#', 'href = "#', $return);
	$return = str_replace(' target = "_blank">', '>', $return);
	return $return;
add_filter('the_content', 'replacesah');
add_filter('comment_text', 'replacesah');

Save the file, and you're done! All links that contain will now be redirected to your Ebates referral link automatically!


  1. says

    Thank you Mitchell! I actually decided to redirect to a page on my site with a short explanation of why I am not promoting ShopAtHome and my recommendation for Ebates. I didn't want to confuse people with ShopAtHome links going directly to Ebates!

    Thanks for the great tips and coding!

Leave a Reply

Your email address will not be published. Required fields are marked *