functions – Display Script in Header When URL Variable Present

Question

I have a script that I want to display in the wp_head, but only if a URL variable is passed. For example, if someone visits https://example.com/?feedback=yes I want the following script to display:

  <script>
    alert( 'Hello, world!' );
  </script>

I can already have this display all the time via the following function, but it’s the part around having it only display if that URL variable exists that I’m not sure on.

/* Describe what the code snippet does so you can remember later on */
add_action('wp_head', 'your_function_name');
function your_function_name(){
?>
  <script>
    alert( 'Hello, world!' );
  </script>
<?php
};

0
Moez Tharani 5 months 2021-06-23T11:53:06-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse