[Support request] Adding Adsense code in header.php (bottom of the page) Not Working

Home Forums Support [Support request] Adding Adsense code in header.php (bottom of the page) Not Working

Home Forums Support Adding Adsense code in header.php (bottom of the page) Not Working

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1523191
    Dailyaim 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&gt;
    <!– 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.

    https://ezgif.com/image-to-datauri/ezgif-7-42be4dff05ac.png

    ============
    Image sample:
    https://ezgif.com/image-to-datauri/ezgif-7-42be4dff05ac.png

    #1523201
    Elvin
    Staff
    Customer Support

    Hi,

    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”.

    A wise man once said:
    "Have you cleared your cache?"

    #1523218
    Dailyaim Limited

    still 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)

    #1523223
    Elvin
    Staff
    Customer Support

    Oh 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>';

    A wise man once said:
    "Have you cleared your cache?"

    #1523232
    Dailyaim Limited

    please where can I find ” that I will replace with this ” ??

    #1523426
    David
    Staff
    Customer Support

    Hi 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 the wp_head hook from the list.
    Set the Priority to 999
    Set the Display Rules to the Entire Site

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