1. Home
  2. ReHub Theme
  3. Affiliate settings
  4. Bulk change for part of affiliate link (affiliate ID)

Bulk change for part of affiliate link (affiliate ID)

It’s very common situation when you have tons of offers on site and you decided to change affiliate ID in all existing links.

We added new plugin which can be used for the same task without coding skills. RH Cloak. You can download it from Rehub – Plugins

Read docs, how to use Rewrite Affiliate Links on site

But if you have basic code skills, better to use code snippet below

I will give you code for this. It will work only for affiliate buttons of theme (for Post offer section, Content Egg templates, offers which you added with Bulk import tool).

add_filter('rh_post_offer_url_filter', 're_link_change_custom_amazon');
function re_link_change_custom_amazon($offer_post_url){
$offer_post_url = str_replace('wpsoul-20', 'wpsoul-50', $offer_post_url);
return $offer_post_url;

instead of wpsoul-20 add your old affiliate ID, instead of wpsoul-50 add your new ID

Paste this code in functions of child theme or grandchild plugin

P.s.1 If you use COntent Egg and change deeplink in one of module, plugin will update your old links after price update for module. Unfortunately, this will not work for Amazon module due technical reason, so, you can use code above

P.s. 2 This code doesn’t change data in your database, instead of this, it will change your affiliate ID on site on fly, when someone open the page

If you want to add some deeplink before all links, use next code

add_filter('rh_post_offer_url_filter', 're_link_change_custom_deep');
function re_link_change_custom_deep($offer_post_url){
$offer_post_url = url_encode($offer_post_url);
return 'https://linksredirect.com/?pub_id=8010524463&source=linkkit&url='.$offer_post_url;

If you want to add some deeplink after original link, add next

add_filter('rh_post_offer_url_filter', 're_link_change_custom_after');
function re_link_change_custom_after($offer_post_url){
return $offer_post_url.'?deeplink=21';