Skip to content

Instantly share code, notes, and snippets.

@shrinkray
Created June 27, 2019 23:04
Show Gist options
  • Select an option

  • Save shrinkray/21c53f5e55387bf32a747b4f741d54a3 to your computer and use it in GitHub Desktop.

Select an option

Save shrinkray/21c53f5e55387bf32a747b4f741d54a3 to your computer and use it in GitHub Desktop.
Given production URL, display code otherwise don't.
<?php
/**
* Comparison adds script if site URL is same as production URL
*
* @returns inline script
*/
$site_url = get_site_url();
$prod_url = 'add-prod-url.com';
if ( $site_url === $prod_url ) { ?>
// this was Google Analytics script but could be anything
<script async src="..."></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-671633-51');
</script>
<?php
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment