[Support request] Please help me add code to my PHP function

Home Forums Support [Support request] Please help me add code to my PHP function

Home Forums Support Please help me add code to my PHP function

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #1052121
    Junaid

    Hello there,
    I want to add my Adsense auto ads code to my AMP version of the site. Please help me to insert auto ads code to AMP version of the site.

    #1052501
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This depends on where you want to add it.

    You can use a widget in Appearance > Widgets.

    You can also use a Hook Elements in our Elements module: https://docs.generatepress.com/article/hooks-element-overview/

    Hope this helps 🙂

    #1052508
    Junaid

    Tom,
    Thank you for your wonderful support. I want to add one code to header of AMP and the other in the body of the AMP version. Can you please guide me in this regard?

    #1052509
    Junaid

    Kindly be specidic in this regard, so that I could easily add codes before </head> and before </body> tags.

    #1052688
    David
    Staff
    Customer Support

    Hi there,

    in the Hook Element you can choose the following hooks:

    WP_head – this is inside the <head></head>
    WP_footer – this appears close to the </body>

    Each hook can be given a priority. A low number (1) places the code first, a higher number moves it down the stack. So a higher priority number is required to move it closer to the </head> or </body>

    #1052709
    Junaid

    I will try it. Will it add code to my AMP version of the site? I’m actually trying to add code to my AMP version of the site.

    #1052711
    Junaid

    I’m sorry but I couldn’t find any option for Hooks in my theme options. Where can I find it?

    #1052765
    David
    Staff
    Customer Support

    in Appearance > GeneratePress activate the Elements module:

    https://docs.generatepress.com/article/hooks-element-overview/

    #1052767
    Junaid

    Well, I got the Hook option. But can you please be specific how can I use this option to add code to AMP version of my site? There are options like,
    Settings
    Display rules
    And in settings there are two options, execute PHP and Execute Shortcodes.

    #1052774
    David
    Staff
    Customer Support

    The two hooks i provided are WP Hooks so should be available in the Amp pages as well.
    To make it so it only appears on Amp pages would require the scripts to be wrapped in a Conditional code, which you would need to ask the Amp plugin author about.

    #1052813
    Junaid

    Thanks, I will try it and let’s see if it works.

    #1052816
    David
    Staff
    Customer Support

    You’re welcome

    #1053064
    Junaid

    I have placed the code but it’s not working. How can I check if the code is placed accurately?

    #1053096
    David
    Staff
    Customer Support

    On the desktop browser – right Click > Inspect. The Dev tools will open and you will see the DOM – expand the <head> and look for the scripts you added.

    Make sure in the Hook Element you set the Display Rules to Entire site.

    #1053458
    Junaid

    Yes, I had set for entire site and selected PHP execution.

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