How to Add Google AdSense Code to Blogger (Without XML Errors)
Let’s be honest. Getting accepted into the Google AdSense program is an amazing feeling. You finally get that approval email, you create your first ad unit, and you rush to your Blogger dashboard to paste the code.
But then you hit "Save," and instead of seeing ads on your site, you are greeted by a massive, frustrating red error message: "Error parsing XML, line X, column Y".
I have been exactly where you are. Almost every new blogger goes through this exact panic moment. Today, I am going to show you exactly why this happens and the easiest way to fix it so your ads start showing up immediately.
Why Does Blogger Reject AdSense Code?
Before we fix it, you need to know why it broke in the first place. Your Blogger template isn't broken, and your AdSense account is perfectly fine.
The issue comes down to the coding language. Google AdSense generates ad tags in standard HTML. However, Blogger themes are built using very strict XML markup.
XML is incredibly sensitive to certain special characters. When it sees raw symbols like the less-than sign (<), greater-than sign (>), or an ampersand (&) in the middle of a template script, it gets completely confused. Blogger thinks the code is broken, so it blocks you from saving the file to protect your website from crashing.
The Solution: Parsing Your AdSense Code
To make Blogger accept your ad code, you need to "parse" it. Parsing simply means taking those problematic HTML characters and converting them into XML-friendly text entities. For example, a < becomes <.
You don't need to do this manually. I got so tired of dealing with this issue that I built a free, instant AdSense Code Converter right here on this website.
Step-by-Step Guide to Placing Your Code
Here is exactly how to safely place your ad code inside your Blogger theme without triggering any errors:
- Copy your Ad Code: Log into your Google AdSense account, go to the 'Ads' section, and copy the snippet for your desired ad unit.
- Parse the Code: Open our AdSense Code Converter tool. Paste your raw AdSense code into the top box, and click the convert button. Copy the new, safe code that it generates for you.
- Open Blogger Theme Editor: Go back to your Blogger dashboard. In the left menu, click on Theme, then click the down arrow next to the 'Customize' button, and select Edit HTML.
- Find the Right Spot: Click anywhere inside the code editor box and press
CTRL + F(or CMD + F on Mac).- If you are pasting the Auto Ads code, search for
</head>and paste your parsed code right above it. - If you are pasting a specific ad unit inside your articles, search for
<data:post.body/>and paste the code right above or below it.
- If you are pasting the Auto Ads code, search for
- Save the Theme: Hit the save icon in the top right corner. Because you used the parsed code, it will save instantly with zero errors!
Alternative Method: Using Layout Gadgets
If you don't feel comfortable messing around inside the Theme's HTML, Blogger offers a safer, code-free alternative.
You can go to the Layout tab in Blogger, click on Add a Gadget (usually in the sidebar or header sections), and select the HTML/JavaScript gadget. Paste your raw AdSense code directly into this box and save it.
Pro tip: You actually don't need to parse your code if you use the Layout Gadget method! Blogger automatically handles the formatting inside gadgets. However, gadgets only let you place ads in specific areas like the sidebar or footer. If you want ads natively inside your articles or header, you will still need to parse the code and use the Theme Editor method.
Final Thoughts
Getting your first ads running should be exciting, not stressful. Just remember the golden rule of Blogger: Never paste raw scripts directly into the XML theme editor. Always run it through a converter first.
Give your site a few minutes after saving the code. It usually takes anywhere from 15 to 30 minutes for new AdSense units to show up and start displaying actual advertisements instead of blank spaces.