Archived topic
Different Header Element Options for AMP Pages
3 replies · Started by Souvik on June 4, 2021
I am using the Generatepress Header Elements on my site. On my site, the AMP is also activated for all my blog posts. Is it possible to create 2 different header elements one for the original page and the other one for the AMP page? Please guide me.
This is my site: https://www.rswebsols.com/
Example blog post link: https://www.rswebsols.com/blogging/business/surprising-expenses-running-website
Example AMP link: https://www.rswebsols.com/blogging/business/surprising-expenses-running-website/amp
Hi there,
You could use this filter: generate_element_display
So, create both Elements and set their Display Rules.
Then, add the filter:
add_filter( 'generate_element_display', function( $display, $element_id ) {
// Tell the non-AMP Element not to appear.
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && 123 === (int) $element_id ) {
$display = false;
}
return $display;
}, 10, 2 );
Then, update the 123 in the above to the Element you do not want to show on the AMP page.
Hope this helps!
It is working! Thank you very much for your help.
You're welcome :)