-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent amp-iframe script from appearing more than once in document #1095
Comments
What is the code you were using to add the 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',
)
);
return $data;
} ); It will prevent duplicates from happening. |
Thanks. This is how I am injecting various scripts in the header, which caused the duplicates I mentioned. function add_amp_scripts() {
?>
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
<script async custom-element="amp-sidebar" src="https://cdn.ampproject.org/v0/amp-sidebar-0.1.js"></script>
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
<script async custom-element="amp-sticky-ad" src="https://cdn.ampproject.org/v0/amp-sticky-ad-1.0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-element="amp-auto-ads" src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js"></script>
<?php
}
add_action( 'amp_post_template_head', 'add_amp_scripts' ); |
@kevinlisota great. If you switch to using the above |
Thanks a lot sir. Scripts appearing more than once were driving me nuts. This fixed them all. |
I need to add an amp-iframe to every page to support prebid user sync, like the instructions here: http://prebid.org/dev-docs/show-prebid-ads-on-amp-pages.html
My first attempt was to simply place the amp-iframe in my AMP footer template and then include the amp-iframe js extension in the header of every page.
However, in the case where there is existing iframe content within the AMP post, this plugin's iframe sanitizer kicks in and adds another copy of the amp-iframe js extension script to the header. This results in the following error:
Next, I tried to insert the amp-iframe element via
the_content
filter, specifically targetingis_amp_endpoint
. That included the amp-iframe element, but did not invoke the santizer to generate the requires amp-iframe script in the header.I'm sure I'm missing something simple here. How would I embed an amp-iframe on every page (needs to be near bottom of page) and ensure that the amp-iframe js script is included once and only once on each page.
The text was updated successfully, but these errors were encountered: