The wordpress blog uses the AMP plugin. How can I manually add the Google adsense ad code under the title of my article without causing an AMP error?

Add the adsense ad code to the appropriate location of the single.php file (different themes are modified in different places, most of them are single.php in the theme directory), and the ads will be displayed below the title. However, directly adding adsense ad code will cause AMP to report an error. Can be achieved by the following code, so that it will not cause AMP error

<?php 
$bIsAmp=$_GET['amp'];
if($bIsAmp===NULL)
{
echo <<<EOF
//Your adsense ad code
EOF;
}
?>

Use the php code to determine whether the current page contains amp parameters. If not, it is a normal page, and then the Google adsense ad code is output, so that AMP will not cause an error.

My blog was modified as shown below

wordpress+amp add google adsense
wordpress+amp add google adsense

发表评论

电子邮件地址不会被公开。 必填项已用*标注