How to resolve Async XML parsing error when saving Google Adsense code in Blogger?

Async Error when saving Google Adsense code in Blogger
If you are a Blogger trying to integrate Google Adsense on your blog, you might have encountered and "async error" if you add the Google Adsense code in Blogger template as it is. Google Adsense provides JavaScript code which can be added to websites and blog platforms to display Google Ads. A typical Google Adsense (asynchronous) Code looks like this:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-XXXXXXXXXXXXXX",
    enable_page_level_ads: true
  });
</script>

The error message on Blogger looks like this:

"Attribute name "async" associated with an element type "script" must be followed by the ' = ' character."
In this post, we will see how to modify the Google Adsense code so that the error is resolve in Blogger templates.


If you get XML parsing error when adding Google Adsense code as it is in Blogger template, then modify the Google Adsense code a bit to resolve the error in Blogger.  A typical Google Adsense (Asynchronouse) code begins with:
<script async src="//pagead2.googlesyndication.com/pagead....</script>
<script>
 .......................................... </script>
 And the error says:
"Attribute name "async" associated with an element type "script" must be followed by the ' = ' character."
Which means, Blogger is expecting an equal sign (=) right after the word "async".

Solution:
Add ="async" right after async in the Google Adsense code.

Before: Orginal Google Adsense code
<script async src="//pagead2.googlesyndication.com/pagead....</script>
<script>
 .......................................... </script>
After: modified
<script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
 After the change, Blogger Template should save successfully without any XML parsing error.

Alternative Way One:

Before:
<script async src="//pagead2.googlesyndication.com/pagead...."</script>

After:
Replace parts of the line containing "async" with the following.

1) Replace the starting part: <script async src=" with &lt;script async src=&quot;
2) Replace the ending part:  "</script> with &quot;&gt;&lt;/script&gt;

So the entire line containing async looks like this:
&lt;script async src=&quot;//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js&quot;&gt;&lt;/script&gt;

Blogger will now save the code without any error.

Alternate Way Two:
If you do not like to fiddle with the Adsense code on your own, you can also take help from online Adsense code parsers such as this Adsense Code Parser (click).

  • Go to the link above and paste the Google Adsense code as it is.
  • Click Convert
  • A parsed code will be generated.
  • Copy the parsed code and paste it in the Blogger template page.
  • Save the Theme.


Comment with Facebook

15 comments:

  1. do you use this same fix on this blog...?

    ReplyDelete
    Replies
    1. Hi,
      Yes I do. Without the edit, Blogger will always throw the XML parsing error.

      Delete
    2. Yea....I was also able to fix it instantly using THIS METHOD HERE

      Delete
  2. Hi,
    Thank you so much for your help! I had no idea how to fix this on my art blog but now no error is showing. :) Have a nice day!
    Diana from ftrabbitstudios.blogspot.com

    ReplyDelete
    Replies
    1. Hi Diana.
      Thanks for your wonderful comment and I am glad the post was of help.
      Cheers! Good Day!

      Delete
  3. how can we know that this modification in code approves the website after verifying?

    ReplyDelete
  4. Thanks it worked. Now waiting for approval :)

    ReplyDelete
    Replies
    1. Did you get approval use this method?

      Delete
  5. wow yes its working now .... :)

    Thanks!
    Albina

    ReplyDelete
  6. This has worked for me. You are a life saver Albina.

    ReplyDelete