How I Manually Added AdSense to My WordPress Website (Step-by-Step)

When I got my AdSense approval, I was excited but also nervous about adding the code to my WordPress site. I didn’t want to use a plugin because I wanted complete control over ad placement and didn’t want to slow down my site with unnecessary plugins.

Let me walk you through exactly how I manually added AdSense to my WordPress website. It’s easier than you think, and I’ll show you every single step.

Why I Chose Manual Installation Over Plugins

Before diving in, let me explain why I went the manual route.

My Reasons:

  • Plugins add extra code that can slow down my site
  • I wanted precise control over where ads appear
  • Some plugins insert ads in annoying places that hurt user experience
  • Manual code gives me flexibility to customize placement
  • One less plugin means fewer security vulnerabilities

That said, if you’re not comfortable with code, plugins like Ad Inserter or Advanced Ads work perfectly fine. But manual installation isn’t hard—I promise.

Step 1: I Got My AdSense Code

The first thing I did was log into my AdSense account and grab the code I needed.

What I Did:

  1. I went to ads.google.com and logged into my approved account
  2. I clicked on “Ads” in the left sidebar
  3. I selected “By ad unit” to create individual ad units
  4. I clicked “+ New ad unit” to create my first ad

My First Ad Setup:

  • I chose “Display ads” (most versatile option)
  • I named it “Header-Display-Ad” so I’d remember where it goes
  • I selected “Responsive” so ads adjust to different screen sizes
  • I clicked “Create”

Google then showed me the ad code. It looked something like this:

html
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXXX"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-XXXXXXXXXXXXXXXX"
     data-ad-slot="XXXXXXXXXX"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

I copied this entire code. I’d need it in the next steps.

Step 2: I Added the AdSense Head Code (Site Verification)

Before placing ads, I needed to verify my site with AdSense by adding code to my site’s header.

How I Did It:

  1. I logged into my WordPress dashboard
  2. I went to Appearance → Theme File Editor
  3. WordPress showed me a warning about editing theme files. I clicked “I understand” because I was being careful
  4. On the right side, I found Theme Header (header.php)
  5. I looked for the </head> closing tag (I used Ctrl+F to search for it)
  6. Right BEFORE the </head> tag, I pasted my AdSense verification code

Important: I made sure to paste it BEFORE </head>, not after. The code needs to be inside the head section.

My Safety Tip: Before making any changes, I clicked “Select All” and copied the entire header.php content to a Notepad file as backup. If something broke, I could paste it back.

After pasting, I clicked “Update File” at the bottom.

Alternative Method (Safer): If you’re using a theme like Astra, GeneratePress, or OceanWP, many have a “Custom Code” section in the theme settings where you can add header code without touching theme files. I actually switched to using this method later because it’s safer during theme updates.

Step 3: I Verified My Site in AdSense

After adding the header code, I went back to my AdSense account.

What I Did:

  1. I clicked on “Sites” in the left sidebar
  2. I clicked “Ready to connect” next to my website
  3. AdSense checked if the code was properly installed
  4. After a few seconds, it said “Your site is connected to AdSense”

If it didn’t verify immediately, I waited 10-15 minutes and checked again. Sometimes Google needs time to crawl and detect the code.

Step 4: I Created Different Ad Units for Different Placements

I didn’t want ads everywhere, so I strategically created specific ad units for specific locations.

The Ad Units I Created:

1. In-Article Ad (my best performer):

  • Ad type: In-article
  • Name: “In-Article-Display”
  • This goes within my blog post content

2. Top of Sidebar Ad:

  • Ad type: Display ads
  • Name: “Sidebar-Top-Display”
  • Size: Responsive

3. Below Post Title Ad:

  • Ad type: Display ads
  • Name: “Below-Title-Display”
  • Size: Responsive

4. End of Content Ad:

  • Ad type: Display ads
  • Name: “End-Content-Display”
  • Size: Responsive

For each ad unit, I copied the code and saved it in a Word document with the ad unit name as a label. This kept me organized.

Step 5: I Added Ads to My Sidebar Manually

The sidebar was easiest because WordPress has built-in widget areas.

What I Did:

  1. I went to Appearance → Widgets
  2. I found my “Primary Sidebar” widget area
  3. I clicked the “+” button to add a new widget
  4. I searched for “Custom HTML” widget and added it
  5. I pasted my sidebar ad code into the Custom HTML widget
  6. I clicked “Update”

Done! My sidebar ad was live.

My Tip: I placed the ad widget after my “About Me” widget but before the recent posts widget. I didn’t put it at the very top because that felt too aggressive.

Step 6: I Added Ads Within Blog Post Content

This was trickier but more effective. I wanted ads to appear naturally within my article content.

Method 1: Manual Insertion in Each Post

For important posts, I manually added ads:

  1. I opened a blog post in the editor (Block Editor/Gutenberg)
  2. I scrolled to where I wanted the ad (usually after 2-3 paragraphs)
  3. I clicked the “+” button to add a new block
  4. I searched for “Custom HTML” block
  5. I pasted my in-article ad code
  6. I updated the post

This works but is time-consuming for every post.

Method 2: Functions.php Code (My Preferred Method)

I added code to my theme’s functions.php file that automatically inserts ads after a specific paragraph in all posts.

What I Did:

  1. I went to Appearance → Theme File Editor
  2. I clicked on Theme Functions (functions.php)
  3. At the very bottom of the file, I added this code:
php
// Insert AdSense after 2nd paragraph
function insert_adsense_after_paragraph($content) {
    // Only show on single posts
    if (is_single()) {
        $ad_code = '
        <div style="margin: 20px 0;">
        <!-- Paste your AdSense code here -->
        <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXXX"
             crossorigin="anonymous"></script>
        <ins class="adsbygoogle"
             style="display:block"
             data-ad-client="ca-pub-XXXXXXXXXXXXXXXX"
             data-ad-slot="XXXXXXXXXX"
             data-ad-format="auto"
             data-full-width-responsive="true"></ins>
        <script>
             (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
        </div>';
        
        // Split content into paragraphs
        $paragraphs = explode('</p>', $content);
        
        // Insert ad after 2nd paragraph
        if (count($paragraphs) > 2) {
            $paragraphs[1] .= $ad_code;
        }
        
        // Join paragraphs back together
        $content = implode('</p>', $paragraphs);
    }
    return $content;
}
add_filter('the_content', 'insert_adsense_after_paragraph');
  1. I replaced the placeholder AdSense code with my actual ad unit code
  2. I clicked “Update File”

Now ads automatically appear after the 2nd paragraph in all my blog posts!

Safety Warning: Editing functions.php can break your site if you make a syntax error. I always kept a backup and tested on a staging site first.

Step 7: I Added Ads Below Post Titles

I wanted an ad right below my blog post titles for maximum visibility.

What I Did:

I added this code to my functions.php file:

php
// Insert AdSense below post title
function insert_adsense_below_title($content) {
    if (is_single()) {
        $ad_code = '
        <div style="margin: 15px 0;">
        <!-- Your AdSense code here -->
        </div>';
        
        $content = $ad_code . $content;
    }
    return $content;
}
add_filter('the_content', 'insert_adsense_below_title');

This places an ad right at the start of the post content, just below the title.

Step 8: I Added Ads at the End of Posts

I also wanted ads at the end of every post, after the conclusion.

The Code I Used:

php
// Insert AdSense at end of post
function insert_adsense_end_of_post($content) {
    if (is_single()) {
        $ad_code = '
        <div style="margin: 20px 0;">
        <!-- Your AdSense code here -->
        </div>';
        
        $content = $content . $ad_code;
    }
    return $content;
}
add_filter('the_content', 'insert_adsense_end_of_post');

Now I had ads at the beginning, middle, and end of posts automatically.

Step 9: I Made My Ads Mobile-Friendly

Since 70% of my traffic comes from mobile, I needed ads to look good on phones.

What I Checked:

  • All my ad units were set to “Responsive” in AdSense
  • I tested every page on my phone to ensure ads weren’t too large
  • I made sure ads didn’t cover content or create annoying popups
  • I verified page speed wasn’t affected significantly

Mobile Optimization Tip: I added this CSS to make ads look better on mobile:

css
/* Make AdSense ads responsive */
.adsbygoogle {
    max-width: 100%;
    overflow: hidden;
}

/* Add spacing around ads on mobile */
@media (max-width: 768px) {
    .adsbygoogle {
        margin: 15px 0;
    }
}

I added this to Appearance → Customize → Additional CSS.

Step 10: I Checked That Ads Were Showing Properly

After adding all the code, I needed to verify everything worked.

My Testing Process:

  1. I cleared my browser cache
  2. I visited my blog in an incognito window (important—logged-in users sometimes don’t see ads)
  3. I checked multiple posts to ensure ads appeared correctly
  4. I tested on mobile using my phone
  5. I used Google’s Mobile-Friendly Test tool

What I Saw First: Blank spaces where ads should be. This is normal! New ad units can take 10-20 minutes to start showing ads.

After 30 Minutes: Ads started appearing. Success!

Common Issues I Faced (And Fixed)

Problem 1: Ads Not Showing

  • Solution: I waited 30 minutes. New ad units take time to activate.

Problem 2: “This Page Can’t Load Google Maps Correctly” Error

  • Solution: I realized I pasted the code incorrectly. I rechecked and fixed the syntax.

Problem 3: Ads Overlapping Content

  • Solution: I added margin CSS around ad divs to create spacing.

Problem 4: Too Many Ads Making Site Look Spammy

  • Solution: I removed some ad placements. Less is more. I kept only high-performing positions.

Problem 5: Slow Page Load Speed

  • Solution: I ensured I was using async AdSense code and limited ad units to 3-4 per page.

My Final Ad Placement Strategy

After testing for two months, here’s what worked best for me:

Homepage: No ads (keeps it clean and fast)

Blog Posts:

  • One ad below the title
  • One ad after 2nd paragraph (in-article)
  • One ad at the end of content
  • One ad in sidebar (top position)

Total: 4 ads per post page. Not too many, not too few.

My Earnings: With 5,000 monthly visitors and this setup, I earn ₹4,500-6,000 monthly.

Alternative: Using a Child Theme (Safer Method)

Later, I learned about child themes and switched to using them for my custom code. This protects my changes when the theme updates.

What I Did:

  1. I created a child theme using a plugin called “Child Theme Configurator”
  2. I moved all my AdSense code to the child theme’s functions.php
  3. Now theme updates don’t delete my code

Much safer long-term!

My Honest Recommendation

Manual AdSense installation gave me complete control, but it requires comfort with basic code. If you’re nervous about breaking your site, use a plugin like Ad Inserter instead.

But if you want maximum control, faster load times, and precise ad placement, manual installation is worth learning. It took me 2 hours the first time, but now I can add AdSense to any WordPress site in 15 minutes.

Start simple. Add one ad to your sidebar using the widget method. Once you’re comfortable, experiment with functions.php for automatic insertions.

Your AdSense setup doesn’t need to be perfect on day one. I’ve adjusted mine dozens of times based on performance data. Start basic, measure results, and optimize over time.

Now go add those ads and start earning from your content!

Leave a Comment