Support » Plugin: AMP » AMP Script Error

  • Resolved Tnace


    I run and I got the message below from Google’s Webmaster Tools. It appears that the amp-ad script is being called twice. I’ve searched all over this plugin but can’t figure out how to fix it and don’t see any support forums on this. Would you be able to help me resolve this AMP issue?


    New Accelerated Mobile Pages issue detected for site

    To owner of,

    Search Console has identified that your site is affected by 1 new Accelerated Mobile Pages related issue. This means that Accelerated Mobile Pages may be negatively affected in Google Search results. We encourage you to fix this issue.

    New issue found:

    The tag ‘amp-ad extension .js script’ appears more than once in the document. This will soon be an error.

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Ryan Kienstra


    Question About Plugins

    Hi @radiocure1,
    Thanks for bringing that up. I also see that warning:

    Are you using any AMP-related plugin or custom code that could be adding the amp-ad extension? The plugin now automatically outputs that extension JavaScript file if it detects the component, like <amp-ad>.

    Thanks Ryan for the quick response! To show ads I’m using Ad Inserter Pro and enabling AMP ads. I believe this is one source of the amp-ad script and it appears the other source may be this plugin? I also have Custom (AMP) Accelerated Mobile Pages installed but just to modify some AMP CSS. Any ideas how to rectify? Sorry, a bit new to using AMP and how it works.


    Plugin Contributor Ryan Kienstra


    Hi @radiocure1,
    Thanks for letting me know which plugins you’re using.

    Is there a place in the UI for the Ad Inserter Pro plugin where a script like this is added?

    <script async custom-element="amp-ad" src=""></script>

    It might look like this:

    That script shouldn’t be needed, as this AMP plugin now detects <amp-ad> in the post content, and adds the scripts.

    • This reply was modified 2 years, 6 months ago by Ryan Kienstra.

    I don’t have that code anywhere from what I see. Not sure how to share a screenshot but below is the code I put into Ad Inserter. Is that not the right code? I’ve also checked the AMP Pages option for the insertion. Please let me know if there’s a way to share a screenshot if you’d like to see one.

    <script async src=”//”></script>
    <!– ST Post Text 1 –>
    <ins class=”adsbygoogle”
    (adsbygoogle = window.adsbygoogle || []).push({});


    <amp-ad width=”100vw” height=320
    <div overflow></div>

    Plugin Contributor Ryan Kienstra


    Hi @radiocure1,
    Thanks for posting the code from the UI. Like you mentioned, that doesn’t look to be the source of the problem.

    Ad Inserter Pro looks to be a paid plugin, so it’s hard to give specific advice:

    But looking at the free version on, here’s a snippet that you can place in your theme’s functions.php file, or a custom plugin. This might prevent that extra script from appearing.

    remove_action( 'amp_post_template_head', 'ai_amp_head_hook', 99999 );

    Could you let me know if that helps? It’d be best to run that on a staging site, or locally.

    It removes an action in the Ad Inserter plugin:

    I’ve inserted the code into Functions.php but still get the error. I’m seeing these two instances of amp-ad js. I can’t figure out where the first one comes from and doesn’t have any tags I can see that attribute what’s inserting it. However, it looks like the second one is this plugin. Is it best to remove one over the other? Could I just remove it from this AMP plugin?

    <script type=’text/javascript’ src=’; async custom-element=”amp-ad”></script>

    <meta name=”generator” content=”AMP Plugin v0.7.0″ /><script async custom-element=”amp-ad” src=””></script&gt; <style amp-custom>

    Plugin Contributor Ryan Kienstra


    Temporary Workaround

    Hi @radiocure1,
    Thanks for trying that snippet in functions.php. Here’s a temporary workaround to use instead:

    add_filter( 'amp_post_template_data', function( $data ) {
    	if ( isset( $data['amp_component_scripts']['amp-ad'] ) ) {
    		unset( $data['amp_component_scripts']['amp-ad'] );
    	return $data;
    } );

    (Building on @westonruter’s response here:

    Some other plugin is probably improperly using the action amp_post_template_head or the filter amp_post_template_data. It would probably be best to also contact other plugin authors, to find out where the issue could be.

    But the snippet above should prevent this plugin from outputting the amp-ad JavaScript file.

    I’m having the same issue with the same plugin, Ad Inserter Pro.

    My issue is that I don’t see the amp-ad script at all. Though the amp-ad tags are appearing.

    They do have a header insert function built into the plugin, to which I have:

    <?php if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { ?>
    <script async custom-element="amp-ad" src=""></script>
    <?php } else { ?> //so on

    But it’s not appearing. Demo url: view-source:

    Plugin Contributor Ryan Kienstra


    Hi @casbboy,
    Thanks for pasting the code that outputs the script. That really helps.

    Could you please upgrade this AMP plugin to the latest version, 0.7.0? That has a way to detect <amp-ad> elements in the post content, and add that script.

    If the script still doesn’t appear, let me know and I’ll help you from there.

    Plugin Contributor Ryan Kienstra


    Question About Workaround

    Hi @radiocure1,
    Have you had a chance to try the workaround above? Thanks!

    Sorry for the delay. That worked perfectly, thanks for all your help Ryan!

    The amp plugin update fixed it. I see:

    <script type=’text/javascript’ src=’; async custom-element=”amp-ad”></script>

    I have the same issue with AMP Plugin Release v1.0-beta1:

    Validation gives me:

    The tag ‘amp-auto-ads extension .js script’ appears more than once in the document.

    Therefore, I added this to functions.php

    add_filter( ‘amp_post_template_data’, function( $data ) {
    $data[‘amp_component_scripts’] = array_merge(
    ‘amp-ad’ => ‘;,
    return $data;
    } );

    It did not seem to do anything. Perhaps I need to add something additional to my header.php.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘AMP Script Error’ is closed to new replies.