Support » Plugin: AMP » Cookie Consent Help Needed

  • Resolved narinder912

    (@narinder912)


    Hi

    I am using this plugin for my blog and I show AdSense ads in AMP pages. Hence I need to show a cookie consent banner.

    ‘AMP by Example’ has given the codes for implementing Cookie Consent in AMP in this page: https://ampbyexample.com/user_consent/basic_user_consent_flow/

    I have read it all, but cannot figure out how to implement the banner with this plugin. I know this maybe outside the scope of the support for this plugin, but for the sake of greater good, can anyone please help with a step-by-step on this? I mean, like where to put the code snippets, etc.

    Best Regards
    Narinder

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

    (@ryankienstra)

    Possible Approach

    Hi @narinder912,
    Sorry for the delay.

    Are you using Legacy Templating, or have yout added theme support for AMP?

    If you’re using Legacy Templating, here’s a way to add an <amp-consent>:

    1. Output the <amp-consent> on a callback for the amp_post_template_footer action:

    
    add_action( 'amp_post_template_footer', function() {
            // Output the <amp-consent>
    } );
    

    2. Add the <amp-consent> component script by filtering amp_post_template_data:

    
    /**
     * Adds the amp-consent component script to the scripts that the AMP plugin outputs.
     *
     * @param array $data Template data.
     * @return array $data Filtered template data.
     */
    add_filter( 'amp_post_template_data', function( $data ) {
    	if ( isset( $data['amp_component_scripts'] ) ) {
    		$data['amp_component_scripts']['amp-consent'] = 'https://cdn.ampproject.org/v0/amp-consent-latest.js';
    	}
    	return $data;
    } );
    
    • This reply was modified 2 years, 10 months ago by Ryan Kienstra.
Viewing 1 replies (of 1 total)
  • The topic ‘Cookie Consent Help Needed’ is closed to new replies.