askdesign
10/22/2015 - 8:39 PM

Add a tracking script to a particular page, just before the </body> tag

Github - Red Blue Concepts

 <?php
 // https://gist.github.com/c4149173b65fddd8bf46.git
 // <script src="https://gist.github.com/redblueconcepts/c4149173b65fddd8bf46.js"></script>
 
 // Don't include the opening php tag
 
 // Add a tracking script to a particular page, just before the </body> tag
 add_action( 'wp_footer', 'tj_add_tracking_scripts' );
 function tj_add_tracking_scripts() {
  global $post;
  
  if ( is_page( 'your-page-slug' ) ) {
  ?>
  
  PASTE YOUR SCRIPT HERE
  
  <?php
  }
  
  if ( is_page( 'your-second-page-slug' ) ) {
  ?>
  
  PASTE YOUR SECOND SCRIPT HERE
  
  <?php
  }
  
  if ( is_page( 'your-third-page-slug' ) ) {
  ?>
  
  PASTE YOUR THIRD SCRIPT HERE
  
  <?php
  }
  
  if ( is_page( 'your-fourth-page-slug' ) ) {
  ?>
  
  PASTE YOUR OTHER SCRIPT HERE
  
  <?php
  }
  
  if ( is_page( 'your-fifth-page-slug' ) ) {
  ?>
  
  PASTE YOUR FIFTH SCRIPT HERE
  
  <?php
  }
 }