[Resolved] Different Header Element Options for AMP Pages

Home Forums Support [Resolved] Different Header Element Options for AMP Pages

Home Forums Support Different Header Element Options for AMP Pages

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1810896
    Souvik

    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

    #1811847
    Tom
    Lead Developer
    Lead Developer

    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!

    #1813859
    Souvik

    It is working! Thank you very much for your help.

    #1815132
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.