Passing through URL parameters does not work for certain links

  • Unknown's avatar

    I’m using the below code to pass through URL parameters for every link on my WordPress site. However, this is not working for certain links. The first ‘Hopsy’ link in the body text of the article does not pass through URL parameters, however, the following ‘Hopsy’ links do. It might be worth noting that the first link is to an Unbounce landing page.

    The code:

    var urlParams = new URLSearchParams(window.location.search);

    $(‘a’).each(function() {
    var $this = $(this);
    var _href = $this.attr(‘href’);
    var fullUrl = _href + ‘?’ + urlParams.toString();
    console.log(fullUrl);
    $this.attr(‘href’, fullUrl);
    });

    Anyone have ideas here?

    Thanks

  • Hi there,

    On what site are you working? The account you’re using to post here does not own any sites on WordPress.com, and it’s not possible to add custom code like that to a WordPress.com site except on our Business Plan.

    If you’re using the open source WordPress software at another host, please ask for help at https://wordpress.org/support/forums instead.

  • The topic ‘Passing through URL parameters does not work for certain links’ is closed to new replies.