Insert Meta Tag before body tag on selected pages only

I am having trouble following these instructions from Hubspot. I would like to only insert the meta tag on the Home Page and Contact Page. So, how do I insert the code?

Specifically, we’ll need to insert some tracking code to the pages of our website, just before the /body tag. The code for that is right here:

<!-- Start of HubSpot Embed Code -->
script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/XXXXXXX.js"></script>
<!-- End of HubSpot Embed Code -->

Hello @rstigers,

Thanks for writing in!

Please use the solution shared in following thread:

Thanks.

And this will be page specific and not site wide?

Hey @rstigers,

The code in the other thread will be applied sitewide. You need something specific in your case. Assuming that you have your child theme already installed and activated,



add_action( 'wp_footer', 'x_print_custom_script' );
function x_print_custom_script(){ ?>
  <?php if ( is_front_page() || is_home() || is_page('Contact') ) : ?>

    <!-- Start of HubSpot Embed Code -->
    <script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/3854478.js"></script>
    <!-- End of HubSpot Embed Code -->
  
  <?php endif; ?>
}

Just make sure that the script loader is the right one from HubSpot and then also make sure that the is_page('Contact') is the exact page title for the contact page.

Please let us know how it goes.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.