• Hello am trying to display ads in my amp pages, but unfortunately I think the codes is wrong, please help me out, thanks in advance

    //Adding Header Code in AMP pages in WordPress
    add_action(‘amp_post_template_head’,’nhb_amp_my_custom_head’);
    function nhb_amp_my_custom_head($amp_template) {
    ?>
    //adsense_header_code
    <?php
    }
    //Adding Footer Code in AMP pages in WordPress
    add_action(‘amp_post_template_footer’,’nhb_amp_my_custom_footer’);
    function nhb_amp_my_custom_footer($amp_template) {
    ?>
    //adsense_body_code
    <?php
    }

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey @froshdimeji,

    Do you have any errors or screenshots to share at all, please? Even in the Chrome developer console do you see any errors there?

    Moreover, I assume the comments //adsense_footer_code etc. are just JS snippets that will load on the page? Have you managed to output anything to the page with this hook?

    I’ve never used AMP pages before but your usage looks correct here, I’m not too sure on the $amp_template var and is your meant to pass in the template so it can return correctly.

    That’s why any screenshots of what you see on the AMP pages, or errors in your logs might help debug further.

    Let us know, and we’ll see if we can take a look.

    Thread Starter froshdimeji

    (@froshdimeji)

    Thanks for your reply, but actually no errors was displayed. It’s just that the code doesn’t perform the operation as expected

    Moderator bcworkz

    (@bcworkz)

    I see the AdSense code on your page, so your code is apparently working. There is a JS error on the page: unexpected token: keyword 'var' This prevents any script from running. There’s nothing wrong with var in of itself, but the JS parser is expecting something else. This could be due to a missing ; in code. Or it could be due to a page optimization flaw. Try turning off optimization of scripts as a test. If that eliminates the error, you’ll need to find a way to get optimized script that’s error free. Sometimes changing the order scripts are loaded can fix optimization. Of course, dependencies must be honored, but some file order might be arbitrary.

    Or there could be an actual typo in the file that loads before the one with the error.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help me to correct this code’ is closed to new replies.