• Resolved unnamed

    (@yazarmfa)


    Hi,

    I am using amp transitional mode. I want the code below to appear only on amp pages.

    <div id="abc"></div>

    I will then format #abc from the custom css field on the wordpress customizer page.

    But I don’t want this code to appear on normal pages. What do I need to do to make it appear only on the amp pages.

    Can you help me?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @yazarmfa

    Thank you for the support topic, you can use amp_is_request() function to execute specific code on AMP endpoint

    eg:

    if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
       ?>
       <div id="abc"></div>
    <?php
    }

    Hope this helps!

    Thread Starter unnamed

    (@yazarmfa)

    Hi,

    Where do I need to add this code to make it appear on all amp pages?

    Plugin Support Milind More

    (@milindmore22)

    Hello @yazarmfa

    There are different hooks available eg: header, footer, body, the placement is dependent on your requirement you can find WordPress hook reference with a quick search

    here is an example of inserting code on every page footer

    add_action( 'wp_footer', function() {
    
      if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
        ?>
         <div id="abc"></div> 
     <?php 
     }
    
    } );
    
    Thread Starter unnamed

    (@yazarmfa)

    Hi again @milindmore22

    This last code solved my problem. This is what I was looking for. Thanks…

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Just Adding Code To Amp Pages’ is closed to new replies.