How To Easily Add Adsense To Wordpress [ultimate Guide]

How to Easily add AdSense to WordPress [Ultimate Guide]

Home » Creations » How to Easily add AdSense to WordPress [Ultimate Guide]

Share with:


Do you want to add AdSense to WordPress? The easiest way to have AdSense is using Plugins, though you’ll learn how to use AdSense on WordPress WITH and WITHOUT Plugins.

You’ll have step by step tutorial about how to apply for AdSense and how to use it on the WordPress site. We will see Ways to add AdSense to WordPress without Plugins, add AdSense to WordPress Manually, and have AdSense on WordPress using Free Plugins.

How to Get Started with AdSense?

Well, now the part begins where we will discuss starting with AdSense. The initial steps until sign-up are the same for all websites, including WordPress. After you are approved, the steps are different for AdSense to WordPress.

First, you need to have a Gmail account, which most of you would already have.

Then, you must go to AdSense Start and fill out a form.

This form is crucial. Google doesn’t want to Advertise on random sites. So it’s better to fill it out carefully. 

Here’s a helpful Pro Tip to add AdSense to WordPress

Pro Tip: If you are having a new site, then it’s recommended to not Apply for AdSense directly. Google doesn’t want to Advertise on incomplete sites. Finish the UI, post 5-6 blog posts, and have a bit of following. Also, a good site load time and site having SSL are preferred.

AdSense approval can sometimes even take a week. But personally for me, I was approved within 36 hours. This was because my 15-day-old site was already indexed on Google search, I already had free SSL from Cloudflare, and my site was fast, even after cheap hosting, and I had seven blog posts published.

What are AdSense Auto Ads and AdSense Ad Units?

There are two significant ways to Add AdSense to WordPress; these two ways, in short, can be called “Auto Ads” and “Ad Units.”

While most people get excited hearing the word “Auto,” I shall say that both are equally good, and it’s about personal preference.

Auto Ads and Ad Units are two significant methods of adding AdSense to WordPress.

Let’s see what these two are in detail.

Auto Ads

Google’s AI understands User behavior; it can test 100s of different ways to find which Ad Placements work best for you. It is suitable for sites with less than 1,000 monthly unique views.

This feature is called “Auto Ads” in AdSense. Below are the Steps for Auto Ads in WordPress.

Auto Ads usually tries lots of variations. Therefore, you need to give it at least a month before you start seeing good results.

So, how to add Google’s Auto Ads to WordPress.

First, Head to AdSense and log in to your AdSense account if you haven’t already. 

Now AdSense -> Ads -> Overview

Then, under the heading, “Let Google place ads for you,” you will see a “Get Code” button.

How To Add Adsense To WordPress

How To Add Adsense To WordPress

 

This will give you a code for your AdSense. The Code has some data unique to you.

Please do not share it with anyone. Throughout this creation, we will show you different images/snippers, in which you would have to replace the Code with your unique AdSense code.

Clicking the Get Code button will give you an Auto Ads code, and Ads will look like this:

Adsense Auto Ads To WordPress

Adsense Auto Ads To WordPress

Ad Unit

You can place your AdSense code at your convenience and choice, too.

To do this, you need to create an Ad Unit in AdSense. Ad unit is a unit of Ads that can be displayed on your site and repeated as you like it. Each Ad Unit can be configured with Settings such as dimensions and Ad Types.

To Create an Ad Unit, Head to AdSense -> Ads -> Overview -> By Ad Unit.

Adsense Ad Units To WordPress

Adsense Ad Units To WordPress

Here, you can choose different Ad Units based on your needs.

It will generate a code; Google asks you to place the Code wherever you want ads.

The Code Google gives is OK. But I have a better approach for you. This will simplify your workflow, give you manual control, and make your site relatively faster.

The Code here looks something like this.

How To Use Adsense Ad Units On Your WordPress Site

How To Use Adsense Ad Units On Your WordPress Site

Now, this Code can be split into two parts: the First Script can be considered one part, and the second script can be regarded as the second.

Parts Of Ad Unit Code

Parts Of Ad Unit Code

These two codes will be put into the Post separately for maximum performance.

Also, in case you want to improve the performance of your WordPress site, do check out 17 Secrets to How I Optimize My WordPress Site To Load In 927 ms (100% GTMetrix)

How to add AdSense to WordPress

Ways To Add Adsense To WordPress

Ways To Add Adsense To WordPress

Once approved for AdSense, you must do the crucial part of using AdSense with WordPress.

There are three primary approaches for AdSense on WordPress.

  1. Add Adsense to WordPress without Plugins
  2. Manually Integrate AdSense and WordPress
  3. Free WordPress AdSense Plugins

We will discuss all of them. Adding WordPress AdSense Without Plugins is my favorite approach. However, it requires an FTP and a bit of control over plugins, though it works great.

Now, some of you do not like to have so many plugins, and as a result, you prefer to have an approach without plugins, basically using your custom code. So now we will discuss everything we did with AdSense, using nothing but our Coding. We will not be using any 3rd Party plugins.

How to add AdSense to WordPress without Plugins

How To Add Adsense To WordPress Without Plugins

How To Add Adsense To WordPress Without Plugins

The Code is easy to customize to ensure an easy workaround for beginners. Some Code is way too intense for even moderately experienced Programmers to understand. So, I suggest you avoid this and move directly to our Next Section of Manually Adding AdSense to WordPress.

If you are still willing to bridge Adsense to WordPress without Plugins, we will show you how.

There are three basic approaches to do that.

  1. Use Google AdSense Auto Ads on WordPress
  2. Place Ad Units for AdSense to WordPress Posts Using Shortcodes

  3. Automated Google Ads Placement Using Repetition

Use Google AdSense Auto Ads on WordPress

 

Now, you need to place this Code on every site page. How to do that?

Well, as we are discussing how to add AdSense to WordPress without Plugins, I will tell you a method for custom code. Don’t worry if you want to do it with plugins; I will tell you the technique later. You can scroll down to “Manually add AdSense to WordPress” for that. For now, let’s focus on doing it without plugins.

So, we are now going to do Google AdSense Auto Ads. Auto Ads use Google’s Algorithm to place ads wherever they are needed automatically.

We already explained how to get Google’s Auto Ads code for your site above; scroll to “What is AdSense Auto Ads and AdSense Ad Units” for that.

Anyways, you need to create a child theme or a custom plugin to add the necessary Code. If you already have a plugin/Child Theme, use that; if not, create a new one. If you don’t know how to create plugins, refer to How to Create Custom Plugins in WordPress

Now below I will share the Code that you need to add to make add AdSense.

WARNING: Google Gives slightly Different Code to each site. Please copy the Code from AdSense and paste it INSIDE the inverted commas of $GoogleCode.

function MilyinScripts(){

	$GoogleCode = '';

	echo $GoogleCode;
}
add_action('wp_head', 'MilyinHead');

This Code will directly Ad Scripts to your WordPress Head, and make it work everywhere on site.

For that, you can directly paste the Code from AdSense in Header.php in your site theme, but it’s not recommended.

Some people prefer to have ads only on their blog posts.

And they question How to use AdSense for WordPress Blog Posts only.

It’s simple, but I will still share the Code for the same.

Note: I love Coding And am willing to help you all. If any reader wants help with anything related to AdSense, you can comment below and I will definitely help you. (It’s free to register)

So here’s the Code to have AdSense only on Posts in WordPress:

WARNING: Google Gives slightly Different Codes to each site. Please copy the code from AdSense and paste it INSIDE the inverted commas of $GoogleCode.

function MilyinScripts(){

	$GoogleCode = '';

	global $post;
	if( !is_preview() && is_single() {
		echo $GoogleCode;
	}
}
add_action('wp_head', 'MilyinHead');

I hope you enjoyed it.

Also, if you want to implement it without the Coding, I will share another method where you can implement it without plugins later in this creation.

Place Ad Units for AdSense to WordPress Posts Using Shortcodes

The first part of the Code is in the Head, as we did earlier.

To place Ads at particular locations, you need to use Ad Units.

We explained how to get the Code for Ad Units earlier. We split the AdSense code into two halves.

The process to add the first part is simple.

WARNING: Google Gives slightly Different Codes to each site. Please copy the code from AdSense and paste it INSIDE the inverted commas of $GoogleCode.

function MilyinScripts(){
	$GoogleCode = '';
	echo $GoogleCode;
}
add_action('wp_head', 'MilyinHead');

The first Code we added above sets up the assets and data from Google to fetch Ads and Advertising information.

But simply having this Code will not add Adsense to WordPress. You need to add the second part of the Code too.

The second part of the Code is (in a way) the actual ad. Wherever the 2nd Code is placed, the ad will be shown.

So, here we will discuss how to convert the 2nd part of the Code into a shortcode for easily inserting in posts.

Below is the Code to build a shortcode. This shortcode placed anywhere inside your Post will output the “2nd Part” of your AdSense Ad Unit code and develop y, our Advertisement. 

WARNING: Google Gives slightly Different Codes to each site. Please copy the code from AdSense and paste it INSIDE the inverted commas of $GoogleCode.

function AdSenseShortcode() {
	ob_start();

	$GoogleCode = '
 (adsbygoogle = window.adsbygoogle || []).push({});';

	global $post;
	if(!is_preview() && is_single()){
		echo $GoogleCode;
	}
	return ob_get_clean();
}
add_shortcode('AdSenseShortcode', 'AdSenseShortcode');

Remember to replace the Code you received from AdSense in $GoogleCode.

This will create a shortcode [AdSenseShortcode]. Wherever you want an advertisement to exist in your Post, put [AdSenseShortcode] instead.

Automated Google Ads Placement Using Repetition

This technique will allow you to automatically insert 2nd part of the Code in your Post at regular intervals.

Remember that you need the first part of the Ad Unit code, too.

The process to add the first part of the Code is the same here also. But I will still explain.

WARNING: Google Gives slightly Different Codes to each site. Please copy the code from AdSense and paste it INSIDE the inverted commas of $GoogleCode.

function MilyinScripts(){
	$GoogleCode = '';
	echo $GoogleCode;
}
add_action('wp_head', 'MilyinHead');

The first Code we added above sets up the assets and data from Google to fetch Ads and Advertising information.

Now, for the second part, we will use automation.

Below is a slightly longer PHP code that automatically adds the second part of the Code to WordPress wherever needed.

There are three things in the given Code you need to change.

$InsertAfter defines the number of paragraphs after which repetition starts. Usually, it is recommended to avoid ads in 5-6 Paragraphs of the Post.

Once the Ad starts inserting, we must decide the gap between 2 consecutive Ads.

$GoogleRepetition defined this gap. I Repeat it after every 4 Paragraphs, but you can change it yourself.

Then $GoogleCode should have your 2nd Part of the AdSense Ad Unit Code that you got. (Remember, the first part of the AdSense Code must be inserted via the codes we discussed earlier.)

For the User Experience Standpoint, I usually wrap my AdSense code in a Div, but you can skip that if you want.

Also, if you are like me and love coding, here are the 23 Most Useful WordPress Code Snippets for Performance, SEO, and Security

function AdBlock( $Content ) {
	if(!is_preview() && is_single()) {
		$InsertAfter = 8; //number of paragraphs to skip before starting Ads
		$GoogleRepetition = 4; // After starting Ads we have repeat after how many paragraphs.

		$GoogleCode = '
';

		$Split = "

";
		$Code = '';
		$Paragraphs = explode( $Split, $Content);

		if ( count( $Paragraphs ) > $InsertAfter ) {
			$i = 1;   // current ad index
			foreach( $Paragraphs as $Paragraph ) {
				if($i > $InsertAfter){
					if($i % $GoogleRepetition == 0){
						 $GoogleAd  = $GoogleCode;
					}
					else {
						$GoogleAd = '';
					}

					$Code.= $GoogleAd . $Paragraph;
				}
				else{
					$Code .=  $Paragraph;     // new text
				}
				$i++;
			}
			return $Code;
		}
		return  $Content;
	}
	return $Content;
}
add_filter('the_content', 'AdBlock');

I hope you like it.

These codes are a bit complex, and I would not recommend trying them if you have 0 experience.

Also, if you want, I can help you with the Code; you can contact me in the comment section or message me by registering on this site for free.

Now, we will see how to implement everything above using Plugins.

How to Add AdSense to WordPress Manually

How To Add Adsense To WordPress Manually

How To Add Adsense To WordPress Manually

You can add AdSense to WordPress manually.

This method is simple and usually good unless you want to implement advanced, strategically placed ads with many variables and conditions clutter.

This is basic yet powerful.

You can Place Ads Manually by 2 Methods:

  1. Use Google AdSense Auto Ads on WordPress
  2. Place Ad Units for AdSense to WordPress Posts Using Shortcodes

Use Google Algorithm to Place Ads Automatically

This is the same as placing Google Auto Ads into your Blog Posts.

You can quickly add Google AdSense to the WordPress site using simple, lightweight plugins.

We have already discussed how to get Auto Ads code in WordPress. So, I will request you to scroll up to read that if needed.

You need to place this Code in your Header.

Well, the easiest way to add Auto Ads to WordPress is by using plugins, most notably the Insert Headers and Footers WordPress plugin,

Install and Activate it, go to its page in wp-admin, and paste the Code below.

WARNING: Google Gives slightly Different Codes to each site. Please copy the code from AdSense and paste it INSIDE the inverted commas of $GoogleCode.

This Code will directly add scripts to your WordPress Head and make it work everywhere on the site.

It’s simple to use and works great.

It would be super easy for you if you are a little bit familiar with the WordPress wp-admin interface.

Place Ad Units for AdSense to WordPress Posts Using Shortcodes

I will show you how to put the AdSense Ad Units code into your Post.

First, you need to have the AdSense Code for the Ad unit.

I have explained it earlier; please scroll above and read that.

This may require WordPress plugins based on Use care, but the benefit of Adding Adsense to WordPress Manually is that you get a lot of control.

You need to place the first part only once in a URL, so I would say put it in Header; the easiest way to add this in WordPress is using the Plugin, most notably the Insert Headers and Footers WordPress plugin.

The second part of the Code should be directly added inside your Post wherever you want your ad to appear.

There is no need for the first part here; just put the second part wherever you want your ads to appear. If you want your Ads to appear at 10 locations, paste the second part of ShortCode at all those 10 locations.

Sometimes, this Code can mess with your Post and conflict with some plugins. So, an even better yet optional approach would be to use a plugin like Shortcoder; in this Plugin, add the 2nd part of the Code and save it.

WARNING: Google Gives slightly Different Codes to each site. Please copy the code from AdSense and paste it INSIDE the inverted commas of $GoogleCode.

 (adsbygoogle = window.adsbygoogle || []).push({});

Now, insert this shortcode in your Post wherever you want ads. It looks clean, is easily editable in the long run, and prevents plugin conflicts.

Now let’s get into Advanced use cases to add AdSense to WordPress.

This is the easiest and most effective for newcomers. I shall say that these would be heavy plugins explicitly built for adding AdSense to WordPress.

Free WordPress AdSense Plugins

How To Use Free Plugins To Add Adsense To WordPress

How To Use Free Plugins To Add Adsense To WordPress

We have some of the Best WordPress Adsense Plugins. All of them are free, as I understand most new business owners have insufficient funds to invest in Paid Plugins.

For people new to WordPress, these plugins feel like heaven; therefore, many love them.

I never use plugins because the best plugins come with many customization options, making my site heavy.

However, when I was new to WordPress, I used Plugins to Add Adsense to my WordPress site.

Some are great, using advanced algorithms to place ads at suitable locations. You cannot quickly achieve this with Code without a Pro.

Besides that, for the majority of busy bloggers, time matters more. 

Most bloggers don’t have time to waste on Coding, and therefore, having a plugin that works flawlessly and reduces your efforts can be constructive.

So, let’s begin.

Easy Google AdSense

Easy Google AdSense is a plugin built for simplicity.

As the same suggests, it is meant to be easy; it manages everything for you. You must put in the AdSense Publisher ID, which will automate everything for you.

It doesn’t give you control and is not customizable. 

However, it is well built and good for performance; it is also easy to operate and reliable.

Quick AdSense

It is an excellent plugin for beginners;even before I learned to code, this was my go-to Plugin because it is simple, easy to use, performance-oriented, and reliable.

It gives you granular control over where to add Adsense to WordPress while still allowing scope for experimentation.

It allows you to randomize and try different Ad Styles, Ad Placements, and Ad Styles without any changes.

This is particularly useful in the early days as it lets you understand what works best for your site.

Google AdSense Dashboard

Google AdSense Dashboard is an excellent plugin. I suggest you try it, even if you use Coding or other manual methods to insert ads.

It allows you to know your AdSense analytics directly from your WordPress dashboard and further allows you to be able to generate reports from then and there.

It’s simple and allows you to understand the data better.

Data is the real king when it comes to cracking the perfect recipe for AdSense.

Advanced Ads

Advanced Ads is an excellent plugin for #AdSense to WordPress. One of the best things about this Plugin is that it includes an Ad Blocker remover.

Netizens using AdBlocker would be asked to remove/disable AdBlocker to view posts.

These Ad Blockers harm Websites’ profits, and therefore, this can give you an additional advantage over the rest of the competition.

Can I use Google AdSense on WordPress?

Yes, AdSense doesn’t have official plugins for WordPress, but you can use AdSense with simple custom codes or 3rd party plugins or use AdSense manually. AdSense can be used with WordPress with a lot of customizations and techniques.

 

What is Google AdSense?

Google Adsense is Google’s Advertising network, which allows Websites and YouTube channels to earn revenue from their content. It mainly focuses on CPC (Cost Per Click), which means you get payment per click. 

Once signed up for AdSense, it gives you a code to start Advertising on your site. How much do you earn? Well, it depends on many factors, including what product is being Advertised, the Location of the Ad Clicker (Clicks from Viewers in the USA, UK, Australia, and Canada generally have higher income), etc.

 

Can I use AdSense on a Free WordPress Site?

No, AdSense is assigned to domains/sites. WordPress.com handles Free WordPress sites, and you cannot apply for them alone. You have to own a domain and fully control it to Apply.

 

Conclusion

#WordPress is excellent, and it has a variety of methods to implement #monetization using AdSense.

If you were lazy enough to ignore the 3000 words above and scroll right to the bottom to read the Conclusion, no worries; I will help you understand everything in short.

I hope you enjoyed my guide on adding AdSense to WordPress; comment below if you have any other approaches or helpful plugin/code you use for AdSense on WordPress.

There are three major approaches to it. Add AdSense to WordPress without plugins using Custom Code. This approach is perfect for Pros who have a bit of knowledge of Code, we implement AdSense using three methods: 

  1. We can use AdSense using Auto Ads or AdSense Ad Units; these can be implemented using WordPress Shortcodes or a code inserting the Ad Unit after regular intervals in your Post.
  2. The following approach to adding AdSense to WordPress is manual, where you paste Code wherever needed. In the case of Auto Ads, this Code is pasted directly into the Header of the theme. For Ad Units, the 1st part of the Code goes in the Header, and the 2nd part of the Ad Unit code is pasted wherever needed. However, you can use plugins like Insert Headers and Footers or Shortcoder to make the work easy. 
  3. The third approach involved directly using plugins to make it work better. All approaches work nicely but this approach is really good for those who don’t want to be involved in Code. These plugins are advanced and built with experience, thus allowing you options to optimize your content better.

In case you face any difficulty, I would gladly help you out. You can comment below, and I will surely help you out.

Aditya AgarwalLast Seen: Sep 22, 2023 @ 5:55am 5SepUTC

Aditya Agarwal

@AkarshitMahajan6300





Published:
Last Updated:
Views: 64
Hasthags:

You may also like

Leave a Reply