Adding stuff after the body tag in WordPress

Today I had to add some retargeting code to a site, and my research revealed that I needed to add it to the functions.php of the theme. No problem.


function jr_add_floodlight_retargeting() {
// Added 4/14/21 by EKB to put code on landing page for Floodlight campaign 
   if ( isset( $_GET['utm_source'] ) ) {
      if($_GET['utm_source'] == "ww") {
        ?>
         ... javascript code here ...
        <?php
      }
   }
} // end function jr_add_floodlight_retargeting
add_action( 'wp_body_open', 'jr_add_floodlight_retargeting' );

But then, my code wasn’t firing properly, and I discovered that the child theme was old enough that it didn’t have the necessary code in header.php. I found out from this article:

WordPress 5.2 action that every theme should use

Added that code to the theme’s header file, and away I went! Yay.