WordPress and Google join forces for faster content access

Automattic, the company running the popular WordPress CMS, has recently announced that it is enabling Google’s “AMP” by default for all WordPress blogs.

What is AMP?

According to Google, the “Accelerated Mobile Pages Project” is an “open source initiative that embodies the vision that publishers can create mobile optimized content once and have it load instantly everywhere.” The main goal of AMP is to speed up the mobile Web.

“The Accelerated Mobile Pages (AMP) Project is an initiative to improve the mobile web and enhance the distribution ecosystem. If content is fast, flexible and beautiful, including compelling and effective ads, we can preserve the open web publishing model as well as the revenue streams so important to the sustainability of quality publishing.”

How does AMP affect your WordPress site?

With this addition, WordPress users will much faster page loads when visitors come to their sites from Google results. In addition to WordPress, hosted sites, WP has also made a plugin available for self-hosted websites,  that automatically converts content as well. Since AMP does not allow things such as third-party JavaScript, you likely will not be able to have lead forms or on-page comments.

AMP is enabled by default for all WordPress.com users and you’ll start seeing speedy results in Google search results with a small lightning bolt next to them to indicate that they’ll load faster.

Is AMP compatible with Google Analytics?

The AMP WordPress plugin does now enable amp-analytics out of the box, but it’s fairly easy to enable.

To enable the AMP WordPress plugin to work with Google Analytics, edit the amp-post-template-actions.php (different file from that previously mentioned) file, either via FTP or within your WordPress Dashboard (go to Plugins > Editor and then select “AMP”), and add the following to the end of it:

 

add_action( 'amp_post_template_head', 'amp_post_template_add_analytics_js' );
function amp_post_template_add_analytics_js( $amp_template ) {
	$post_id = $amp_template->get( 'post_id' );
	?>
	<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
	<?php
}

add_action( 'amp_post_template_footer', 'xyz_amp_add_analytics' );

function xyz_amp_add_analytics( $amp_template ) {
    $post_id = $amp_template->get( 'post_id' );
    ?>
	<amp-analytics type="googleanalytics" id="analytics1">
	<script type="application/json">
	{
	  "vars": {
		"account": "UA-XXXXX-Y"
	  },
	  "triggers": {
		"trackPageview": {
		  "on": "visible",
		  "request": "pageview"
		}
	  }
	}
	</script>
	</amp-analytics>
    <?php
}

 

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *