Mehul Panchal
Mehul Panchal

Reputation: 3

Connecting Google Analytics to Wordpress website

<?php
/**
 * electro engine room
 *
 * @package electro
 */

/**
 * Initialize all the things.
 */
require get_template_directory() . '/inc/init.php';

/**
 * Note: Do not add any custom code here. Please use a child theme so that your customizations aren't lost during updates.
 * http://codex.wordpress.org/Child_Themes
 */
 
 /**
Change Tag to Manufacture
 */
 
add_filter('gettext', 'bbloomer_translate_tag_taxonomy');
add_filter( 'ngettext', 'bbloomer_translate_tag_taxonomy' );
 
function bbloomer_translate_tag_taxonomy($translated) {
 
if ( is_product() ) {
// This will only trigger on the single product page
$translated = str_ireplace('tag', 'Manufacture', $translated);
}
 
return $translated;
}

<?php
add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>
 
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-176552663-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-176552663-1');
</script>
 
<?php } ?>

ERROR "Your PHP code changes were rolled back due to an error on line 35 of file wp-content/themes/electro/functions.php. Please fix and try saving again. syntax error, unexpected '<', expecting end of file"

Can anyone solve this ?

Upvotes: 0

Views: 221

Answers (1)

You're reopening <?php tag on line 35, just remove the duplicate tag. ;-)

Upvotes: 1

Related Questions