How To Use The Destination URL Instead Of Cloaked URL With Autolinker (Skimlinks Compatibility)

  • Knowledge Base
  • How To Use The Destination URL Instead Of Cloaked URL With Autolinker (Skimlinks Compatibility)

In some affiliate programs like Skimlinks, they detect external links on your blog by using an on-page javascript that you have to load on your site.

This poses a problem because ThirstyAffiliates when paired with the Autolinker, will automatically use the cloaked affiliate link.

We created this snippet of code which tells the Autolinker to use the destination URL instead of the cloaked URL which means it’s now compatible with tools like Skimlinks.

function swapDestinationURLAutolinker($linkAttributes, $linkID) {
    if (!is_admin()) {
        $linkData = unserialize(get_post_meta($linkID, 'thirstyData', true));
        $destinationUrl = htmlspecialchars_decode($linkData['linkurl'], ENT_COMPAT);
        $linkAttributes['href'] = $destinationUrl;
    }

    return $linkAttributes;
}

add_filter('thirstyFilterLinkAttributesBeforeInsert', 'swapDestinationURLAutolinker', 10, 2);
in