Making WordPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.