title: How to keep query string parameters as user navigates through the website
body: <p>I have a situation where I want to preserve a query string between clicks on my Wordpress website.</p>
  
  <p>E.g.
  www.mywebsite.com/?utm_source=mysource</p>
  
  <p>When navigating from this link to another page of the website that query string should persist.</p>
  
  <p>E.g. 
  www.mywebsite.com/anotherpage/?utm_source=mysource</p>
  
  <p>So I decided one easy way to do this would be to modify the javascript so that my function is fired when a click on an anchor tag occurs.</p>
  
  <pre><code>//Ensures that the query string persists between clicks on the site
    $("a").on("click", function (event) {
      event.preventDefault();   
      window.location.href = event.currentTarget.href + window.location.search;  
    });
  </code></pre>
  
  <p>However this doesn't work for other elements on the page like buttons which are not anchor tags but still contain hrefs that modifiy the window location when they are clicked. For example in the php scripts of the theme there is code such as:</p>
  
  <pre><code>&lt;button onClick="location.href=www.anotherwebsite.com"&lt;/button&gt;
  </code></pre>
  
  <p>I could implement another function that implements the same behavior for button elements but I am concerned that whenever another element is added I will have to check for a new type. Is there a better way to ensure that whenever the window location is changed my query string persists? </p>
  
  <p>FYI: I am not allowed to put the information in a cookie which is another way I thought of keeping track of the parameters.</p>