Archived topic
Please help me add code to my PHP function
17 replies · Started by Junaid on November 3, 2019
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.
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 :)
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?
Kindly be specidic in this regard, so that I could easily add codes before </head> and before </body> tags.
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>
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.
I'm sorry but I couldn't find any option for Hooks in my theme options. Where can I find it?
in Appearance > GeneratePress activate the Elements module:
https://docs.generatepress.com/article/hooks-element-overview/
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.
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.
Thanks, I will try it and let's see if it works.
You're welcome
I have placed the code but it's not working. How can I check if the code is placed accurately?
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.
Yes, I had set for entire site and selected PHP execution.