Disable New Relic for AMP in WordPress

Posted by: Alex on July 19, 2016

If you’re a pretty techy web dev worth your salt you’ll love playing with new technologies. That may have led you down the path of trying out both New Relic for performance monitoring of servers and AMP – the new lightweight way of serving websites specifically for mobile.

In doing so you may find that your AMP pages are not valid, this is due to New Relic injecting JavaScript into the beginning of your webpages for its speed tracking purposes. Google/AMP will then not see your webpage as valid AMP markup due to this JavaScript – and as such you won’t rank or gain any benefit from having AMP installed.

The easiest way to stop this if you’re using the WordPress AMP plugin is to go to Plugin Editor and add the following code to the top of amp/amp.php

if (extension_loaded('newrelic')) {
  newrelic_disable_autorum();
  newrelic_ignore_transaction();
}
newrelic_disable_autorum();

newrelic_ignore_transaction();