RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Include Google’s platform.js Into Your WordPress Footer

In a number of articles we intend on publishing on our website, Googel's platform.js JavaScript code will be referenced over and over. Rather than include it in very article, we've included the code here for reference. For the sake of convenience, we've included a WordPress plugin... although using the code in your custom functions file is almost always a more prudent option.

While the code may be rendered anywhere on your page, Google recommends the footer as it may improve load time. The only exception is when using any of the JavaScript API methods; the API code needs to be placed in the page after the script inclusion.

By itself this code doesn't perform any function. Its purpose is to support various Google related posts Tag: google on our blog.

WordPress Function

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

1
<?php 
2
/*
3
 Include Google's platform.js Into Your WordPress Footer
4
 http://www.beliefmedia.com/code/wp-snippets/google-javascript-footer
5
*/
6
 
7
function beliefmedia_google_platformjs() {
8
 echo '<script src="https://apis.google.com/js/platform.js" async defer></script>';
9
}
10
add_action('wp_footer', 'beliefmedia_google_platformjs');

■ ■ ■

Alternatives

If you were to use the dynamic code (no longer used by us for most of our shortcodes), the following will add the JavaScript to the WP footer. It is required that it be rendered after the last widget tag (the footer will do this).

1
<?php 
2
/*
3
 Include Google's platform.js Into Your WordPress Footer
4
 http://www.beliefmedia.com/code/wp-snippets/google-javascript-footer
5
*/
6
 
7
function beliefmedia_google_platformjs() {
8
?>
9
  <script type="text/javascript">
10
    (function() {
11
      var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
12
      po.src = 'https://apis.google.com/js/platform.js';
13
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
14
    })();
15
  </script>
16
<?php
17
}
18
add_action('wp_footer', 'beliefmedia_google_platformjs');

If adding language, or if you'reusing onload callback to execute code after all dependencies have loaded, use the following.

1
<?php 
2
/*
3
 Include Google's platform.js Into Your WordPress Footer
4
 http://www.beliefmedia.com/code/wp-snippets/google-javascript-footer
5
*/
6
 
7
function beliefmedia_google_platformjs() {
8
 echo '<script src="https://apis.google.com/js/platform.js" async defer></script>';
9
}
10
add_action('wp_footer', 'beliefmedia_google_platformjs');

More details are available on Google's developer website .

PHP Code

Used outside of WP, the function is virtually identical.

1
<?php 
2
/*
3
 Include Google's platform.js With PHP
4
 http://www.beliefmedia.com/code/wp-snippets/google-javascript-footer
5
*/
6
 
7
function beliefmedia_google_platformjs() {
8
?>
9
 <script >
10
   window.___gcfg = {
11
     lang: 'zh-CN',
12
     parsetags: 'onload'   };
13
 </script>
14
 <script src="https://apis.google.com/js/platform.js" async defer></script>
15
<?php
16
}

Note: All the Google functions have changed since we first published similar code on Internoetics. It's the first JavaScript block that's made available in the downloads below.

Download

This download is no longer available.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment