• Resolved kushald

    (@kushald)


    We’re working with a partner who is trying to load amp-access-scroll by adding it in a filter like so.

    add_filter( 'amp_post_template_data', array( $this, 'amp_component_scripts' ), 99 );
    
    public function amp_component_scripts( $data = [] ) {
    
            $data['amp_component_scripts']['amp-access']        = 'https://cdn.ampproject.org/v0/amp-access-0.1.js';
            $data['amp_component_scripts']['amp-access-scroll'] = 'https://cdn.ampproject.org/v0/amp-access-scroll-0.1.js';
    
            return $data;
        }

    However, amp-access loads but amp-access-scroll does not. Is it possible the sanitizer is removing amp-access-scroll because there is no corresponding element or attribute to show that it is being used? If so, is there a way to override this behavior for our extension? Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    You no longer should need to manually add amp_component_scripts with such a filter. The plugin should be automatically adding the scripts when they are needed on the page. If the script is not needed on the page, then it is removed automatically.

    If this is being removed even though you are adding it, then this is a bug in the detection logic.

    Can you share the full markup that you are adding to the page which depends on this script component? I guess it is the script#amp-access element that goes in the head and then element that has the amp-access="NOT scroll.scroll" attribute in the body? I admit I have no familiarity with this component, so if you can share how you’re intending to use it according to proper usage, that will be helpful.

    Thread Starter kushald

    (@kushald)

    Thanks for the fast reply! Your guess is exactly right. And in particular there is no attribute or tag name that would help us know that we want to load the Scroll extension without peeking into the two values you mention. I can’t share the code for the actual page in question, but conceptually it is the same as https://github.com/ampproject/amphtml/blob/master/examples/scroll.amp.html

    Thread Starter kushald

    (@kushald)

    (It also looks like it’s possible to work around this issue for now by enqueuing this script tag in amp_post_template_head, is there any concern there we’re missing if we use this as a stopgap?)

    • This reply was modified 5 years, 2 months ago by kushald.
    Plugin Author Weston Ruter

    (@westonruter)

    @kushald Yes, that will work fine. You can also just output it the at the same point where you output the section[amp-access] element, and the AMP plugin will automatically move the scripts to the head. That would have the advantage of not depending on the amp_post_template_head action, which is only applicable in the AMP Legacy template.

    I’ve filed a bug for this: https://github.com/ampproject/amp-wp/issues/5999

    Thread Starter kushald

    (@kushald)

    Got it, thank you!!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Problems making AMP extension load’ is closed to new replies.