phpwordpressamp-htmlgoogle-developers-console

AMP warning as "An AMP component 'script' tag is present more than once in the document"


I'm facing an issue the warning in AMP pages since last month as "An AMP component 'script' tag is present more than once in the document.".i tried to remove the duplicate script from the AMP, but cant able to find. i don't know weather it came from the plugin or somewhere else...


Solution

  • To stop the auto injection, simply add the following code to your functions.php

    add_filter( 'amp_post_template_data', function( $data ) {
        $data['amp_component_scripts'] = array_merge(
            $data['amp_component_scripts'],
            array(
                'amp-iframe' => 'https://cdn.ampproject.org/v0/amp-iframe-latest.js',
                'amp-analytics' => 'https://cdn.ampproject.org/v0/amp-analytics-latest.js',
                'amp-sticky-ad' => 'https://cdn.ampproject.org/v0/amp-sticky-ad-latest.js',
                'amp-form' => 'https://cdn.ampproject.org/v0/amp-form-latest.js',
                'amp-ad' => 'https://cdn.ampproject.org/v0/amp-ad-latest.js',
            )
        );
        return $data;
    } );
    

    Ref : Click Here