Google AdSense for WordPress – No Plugin Needed

Adding Google AdSense ads to your WordPress blog was a tedious task. Either you needed to manually modify your theme, or you had to use a plugin, such as Google’s own AdSense plugin. Even then, placements were limited, and handling both mobile and desktop themes was complicated at best. Recently, two things have changed: Google retired the AdSense plugin and introduced Auto Ads.

At first, the situation seemed like it had turned for the worse. Without the official plugin, you had to resort to using a third-party plugin or manually placing ads in your theme. But Auto Ads made things much simpler. Instead of having to manually place your ads, you can let Google do it for you. It works great on both desktop and mobile themes.

The easiest way to enable Auto Ads is by using a child theme. First, you need to get the Auto Ads ad code. Next, in your child theme’s functions.php, add the following lines, making sure to replace the javascript snippet with your own.

// Add Google AdSense
function my_google_adsense_header() {
?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({
          google_ad_client: "ca-pub-4066984350135216",
          enable_page_level_ads: true
     });
</script>
<?php
}
add_action( 'wp_head', 'my_google_adsense_header');

Leave a Reply

Your email address will not be published. Required fields are marked *