Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
JS to update URLs on click breaks Elementor Popups

I am currently using the following code in order to automatically prepend affiliate URLs with my affiliate ID:

`add_action('wp_footer', 'auto_affiliate_url');
function auto_affiliate_url()
{ 
?>

<script>
jQuery(document).ready(function ($) {

      // adairs affiliate URL for redirect
      var adairsaffURL = "https://t.example.com/12345/t/54321?Url=";
      // bedthreads affiliate URL for redirect
      var bedthreadsaffURL = "https://t.example.com/12121/t/21212?Url=";

      // function called when link is clicked
      addAffiliate = function(link) {
        var redirectUrl = link.href;
        if (redirectUrl.indexOf('adairs.com.au') > 0) {
          redirectUrl = adairsaffURL + escape(redirectUrl);
        } else if (redirectUrl.indexOf('bedthreads.com.au') > 0) {
          redirectUrl = bedthreadsaffURL + escape(redirectUrl);
        }
        link.href = redirectUrl;
        return true;
      }

      $("a").click(function(event) {
        addAffiliate(this);
      });


    });
</script>

<?php
}`

This works well, however it creates an issue when attempting to open pop ups in Elementor, as it appends something like this to the URL without opening the pop-up:

#elementor-action%3Aaction%3Dpopup%3Aopen%26settings%3DeyJpZCI6IjM3NjgiLCJ0b2dnbGUiOmZhbHNlfQ%3D%3D

Elementor includes these event triggers, but I am not sure if they are useful in this case.

I would like this code to run only if the click is not for a pop up or internal link. I have tried using if ((link.href).indexOf(location.host) < 0 before the function with no luck. Any help would be much appreciated.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!