close

Info

  • 加入 js 檔案時,也可以同時設定引用 jQuery 等 lib
  • add_action('wp_enqueue_scripts', 'gtm_scripts');
    function gtm_scripts() {
        // product category page
        if (is_product_category()) {
            wp_enqueue_script('product-category', get_stylesheet_directory_uri() . "/js/gtm/product_category.js", array('jquery'));
            return;
        }
    }
  • 要注意的是引用 jQuery 後因為避免版本衝突,引用的 js 中不能使用「$」要改用「jQuery」
  • jQuery(function() {
      console.log('GTM product-category page');
      dataLayer.push({'event': 'catpg'});
    });

Reference

  1. https://developer.wordpress.org/reference/functions/wp_enqueue_script/
arrow
arrow
    文章標籤
    PHP WordPress
    全站熱搜

    danielhuang030 發表在 痞客邦 留言(0) 人氣()