将 Google Analytics 连接到 Wordpress 网站

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 } ?>

错误 “由于文件 wp-content/themes/electro/functions.php 第 35 行的错误,您的 PHP 代码更改被回滚。请修复并再次尝试保存。 语法错误,意外的“<”,预期文件结束

谁能解决这个问题?

您要在 line 35 上重新打开 <?php 标签,只需删除重复标签即可。 ;-)