How to Remove Old AdSense Code from Your WordPress Blog

If you previously added AdSense code to your WordPress blog but don’t remember where you placed it, don’t worry! There are multiple places where the code might be hiding. In this guide, I’ll walk you through different methods to find and remove your old AdSense code so you can replace it with your new AdSense account.


Step 1: Check the Theme File Editor for Hardcoded AdSense Code

If you manually added AdSense code to your theme files, follow these steps to find and remove it:

1. Open the Theme File Editor

  • Log in to your WordPress Dashboard.
  • Go to Appearance > Theme File Editor.

2. Check Common Files for AdSense Code

Look for AdSense code (<script>, adsbygoogle, or google_ad_client) inside these files:

  • header.php (Usually inside <head>)
  • footer.php (At the bottom, before </body>)
  • single.php (If you added ads to blog posts)
  • sidebar.php (If ads were in the sidebar)
  • functions.php (Check if you used add_action to insert ads)

3. Remove the AdSense Code

Once you find the AdSense code, delete it and click Update File.


Step 2: Check the Widget Section

If you used a widget to place AdSense ads, follow these steps:

  1. Go to Appearance > Widgets.
  2. Look for Custom HTML, Text, or AdSense widgets.
  3. Click on the widget and check if it contains any AdSense script.
  4. Remove the code and click Save Changes.

Step 3: Check the Theme Customizer

Some themes allow adding scripts via the WordPress Customizer:

  1. Go to Appearance > Customize.
  2. Check Additional CSS or Custom Scripts.
  3. If you find AdSense code, remove it and click Publish.

Step 4: Check Plugin Settings

You might have used an AdSense plugin to insert ads.

  1. Go to Plugins > Installed Plugins.
  2. Look for plugins like Ad Inserter, Advanced Ads, WP Simple AdSense Insertion.
  3. If you find one, open its settings and check for any AdSense code.
  4. Remove or replace it with the new AdSense code.

Step 5: Check the Database (For Advanced Users)

If you added AdSense directly to your posts or pages, you can find and remove it from the database.

  1. Go to phpMyAdmin in your hosting control panel.
  2. Select your WordPress database.
  3. Click on the wp_posts table.
  4. Use the Search feature to look for adsbygoogle or your old AdSense publisher ID.
  5. If you find it inside any post content, edit and remove it.

⚠️ Warning: Always back up your database before making changes!


Step 6: Check Third-Party Code Injection Tools

If you used a third-party tool to insert ads, check:

  • Site Kit by Google (Go to Site Kit settings)
  • Header and Footer Scripts Plugin (Check settings under “Settings > Insert Headers and Footers”)

Remove any old AdSense code from these tools.


Final Step: Clear Cache and Test Your Site

After removing the AdSense code:

  • Clear your WordPress cache (if using a caching plugin like WP Rocket or W3 Total Cache).
  • Check your website’s source code (Right-click > View Page Source, then search for “adsbygoogle”).
  • Test your site to ensure old ads are gone.

Conclusion

By following these steps, you can successfully remove all traces of your old AdSense code and replace it with your new one. If you’re still seeing old ads, try waiting a few hours, as changes may take time to reflect.

Scroll to Top