• Resolved yoni y

    (@yoni-y)


    Hi I’m looking into adding amp to a wordpress site.
    One thing I’m not sure about is how do I add content that should only be available for the amp version and not the regular version and vice versa.

    For example if I have an iframe for a contact form I will wont the regular page to have the regular form code <div><script>//script to load form…</script></div> and the <amp-iframe …> for the amp page.

    Is there any way for me to only include the regular content on the regular page and the amp content only on the amp page?

    Currently both content is included in both pages (after striping non supported tags from the amp version).

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

    (@westonruter)

    Yes, a good way to do this is to utilize a shortcode that does the switching between the two different versions. For example:

    add_shortcode( 'contact_form', function() {
        if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
            return '<amp-iframe...';
        } else {
            return '<div>script...';
        }
    } );

    Otherwise, you could use a custom sanitizer to do the replacement after the page has been generated, but generally it is better (and easier) to do the switching at page generation time.

    Thread Starter yoni y

    (@yoni-y)

    Thank you for replying Weston.
    I was actually wondering if there is some generic shortcode already builtin with the plugin like [amp-only] [amp-exclude] so I wont have to add them myself.

    Plugin Author Weston Ruter

    (@westonruter)

    The plugin does not come built-in with such plugins at this time.

    Thread Starter yoni y

    (@yoni-y)

    Bummer.
    Would you care for a pull request or is it a feature you don’t want to add in?

    Plugin Author Weston Ruter

    (@westonruter)

    I’m not sure. I suggest opening a GitHub issue for discussion.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Creating unique content for AMP’ is closed to new replies.