Making WordPress.org

Changeset 9195


Ignore:
Timestamp:
10/17/2019 05:16:38 AM (6 years ago)
Author:
dd32
Message:

WordPress.org: Load Google Tag Manager through an mu-plugin rather than loading it manually in many themes.

See #4625.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/front-page.php

    r9183 r9195  
    99
    1010    <body <?php body_class( 'folded' ); ?>>
    11         <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P24PF4B" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
     11        <?php wp_body_open(); ?>
    1212        <div class="gutenberg">
    1313            <div id="editor" class="gutenberg__editor"></div>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/gutenberg/functions.php

    r9183 r9195  
    10291029
    10301030add_filter( 'handbook_display_toc', '__return_false' );
    1031 
    1032 /**
    1033  * Output the GoogleTagManager <head> tags.
    1034  */
    1035 function wporg_gutenberg_gtm() {
    1036     ?>
    1037 
    1038     <link rel="dns-prefetch" href="//www.googletagmanager.com">
    1039 
    1040     <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    1041     new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    1042     j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    1043     'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    1044     })(window,document,'script','dataLayer','GTM-P24PF4B');</script>
    1045 
    1046     <?php
    1047 }
    1048 add_action( 'wp_head', 'wporg_gutenberg_gtm' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/functions.php

    r9169 r9195  
    133133
    134134/**
    135  * Output the GoogleTagManager <head> tags.
    136  */
    137 function wporg_login_gtm() {
    138     ?>
    139     <link rel="dns-prefetch" href="//www.googletagmanager.com">
    140 
    141     <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    142     new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    143     j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    144     'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    145     })(window,document,'script','dataLayer','GTM-P24PF4B');</script>
    146     <?php
    147 }
    148 add_action( 'wp_head', 'wporg_login_gtm' );
    149 add_action( 'login_head', 'wporg_login_gtm' );
    150 
    151 /**
    152135 * wp_die() handler for login.wordpress.org, adds GTM to error pages.
    153136 */
    154137function wporg_login_die_handler( $message, $title = '', $args = array() ) {
    155     if ( is_string( $message ) ) {
     138    if ( is_string( $message ) && is_callable( '\WordPressdotorg\Plugin\GoogleTagManager\wp_head' ) ) {
    156139        ob_start();
    157         wporg_login_gtm();
     140
     141        \WordPressdotorg\Plugin\GoogleTagManager\wp_head();
     142        \WordPressdotorg\Plugin\GoogleTagManager\wp_body_open();
     143
    158144        $gtm = ob_get_clean();
    159145
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-login/header.php

    r9155 r9195  
    1717<body <?php body_class( 'wp-core-ui login no-js' ); ?>>
    1818<script type="text/javascript">document.body.className = document.body.className.replace('no-js','js');</script>
    19 <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P24PF4B" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
     19<?php wp_body_open(); ?>
    2020
    2121<div id="login">
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/page-download-counter.php

    r8277 r9195  
    6666    number_format_i18n( $num )
    6767);
     68
     69// Remove some headers we don't need:
     70remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
     71remove_action( 'wp_head', 'wp_print_styles', 8 );
     72remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
     73remove_action( 'wp_head', '_admin_bar_bump_cb' );
    6874
    6975?>
     
    7682    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    7783    <link rel="canonical" href="<?php echo esc_url( $canonical_url ); ?>">
    78     <link rel="dns-prefetch" href="//www.googletagmanager.com">
    7984    <meta name="description" content="<?php echo esc_attr( $meta_desc_text ); ?>">
    80     <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    81 new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    82 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    83 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    84 })(window,document,'script','dataLayer','GTM-P24PF4B');</script>
    8585    <style type="text/css">
    8686        html,
     
    215215        }
    216216    </style>
     217    <?php wp_head(); ?>
    217218</head>
    218219
    219220<body>
    220     <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P24PF4B" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
     221    <?php wp_body_open(); ?>
    221222    <div class="something-semantic">
    222223        <div class="something-else-semantic">
Note: See TracChangeset for help on using the changeset viewer.