- This topic has 5 replies, 3 voices, and was last updated 3 years, 5 months ago by David.
-
AuthorPosts
-
November 8, 2020 at 8:07 pm #1523191Dailyaim Limited
I have tried applying the same strategy I use on all WordPress themes (I am using for all my sites) on my GeneratePress theme and it failed. My host confirmed I contact my theme vendor.
One of the best position to apply google AdSense code for better conversion is placing the AdSense code at the bottom header.php, to enable the adsense display both on single and homepage. But it’s not working here.
This is the error I get whenever I paste the code and try saving it, I get this error notification (won’t save);
“Your PHP code changes were rolled back due to an error on line 81 of file wp-content/themes/generatepress/header.php. Please fix and try saving again.
syntax error, unexpected ‘<‘, expecting end of file”
Here is the adsense code:
<script async src=”https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
<!– Responsive Ad –>
<ins class=”adsbygoogle”
style=”display:block”
data-ad-client=”ca-pub-####################”
data-ad-slot=”790538100″
data-ad-format=”auto”
data-full-width-responsive=”true”>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>See the image below, showing the codes and position I tried placing the code.
============
Image sample:
https://ezgif.com/image-to-datauri/ezgif-7-42be4dff05ac.pngNovember 8, 2020 at 8:13 pm #1523201ElvinStaffCustomer SupportHi,
Try this instead.
echo '<script async src=”https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script> <!– Responsive Ad –> <ins class=”adsbygoogle” style=”display:block” data-ad-client=”ca-pub-####################” data-ad-slot=”790538100″ data-ad-format=”auto” data-full-width-responsive=”true”> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>';
Alternatively, you can use a Hooks Element. – https://docs.generatepress.com/article/hooks-element-overview/
Place your script in the code area and hook it to
wp_head
. You then set the display rule to “Entire site”.November 8, 2020 at 8:37 pm #1523218Dailyaim Limitedstill getting the same error;
Your PHP code changes were rolled back due to an error on line 80 of file wp-content/themes/generatepress/header.php. Please fix and try saving again.
syntax error, unexpected ”<script async src=”https://’ (T_ENCAPSED_AND_WHITESPACE)
November 8, 2020 at 8:50 pm #1523223ElvinStaffCustomer SupportOh right, Let’s replace these
”
with this"
.Try this:
echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!– Responsive Ad –> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-####################" data-ad-slot="790538100" data-ad-format="auto" data-full-width-responsive="true"> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>';
November 8, 2020 at 9:01 pm #1523232Dailyaim Limitedplease where can I find ” that I will replace with this ” ??
November 9, 2020 at 1:47 am #1523426DavidStaffCustomer SupportHi there,
DO NOT edit the Theme Template files. Any changes to this file will be lost when the theme is updated.
Instead create a new Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
Paste in your Adsense code to the Hook content.
Select thewp_head
hook from the list.
Set the Priority to999
Set the Display Rules to theEntire Site
-
AuthorPosts
- You must be logged in to reply to this topic.