How to insert ads without plugins WordPress (Adsense)

Today I want to explain how to insert ads without plugins (Adsense). This time I will talk about a way to insert ad units, which, according to the statements of many webmasters, can significantly increase the earnings of the contextual blocks of Adsense. As you can see in the title, we are talking about inserting Google ads directly into the body of the article. Such a method is not suitable for all bloggers. But the fact remains, it increases the number of clicks, increases the cost of each click, and as a result, has a positive effect on the maximum benefit of your blog or website.insert ads without plugins

insert ads without plugins

I myself have tried to use this method of insertion of context blocks, and I mean, that the result met expectations. It is still too early to make a final statement, but earnings growth shows. Later, for sure, I’ll write about the results in a separate article.

So, today I would like to explain how to insert ads in the article without plugins, in a fairly easy and fast way.

Another important point. You can insert AdSense ad units within the article fully automatically. With the use of WordPress plugins, there are actually many. But I refused this option.

First of all, I’ve picked up a rule for myself – fewer plug-ins on your blog – more speed. Web works faster and more stable.

Secondly, I do not like the automatic placement of ads on my websites. All articles on the web are different. Another structure, the volume, with different numbers of images. And it would not be very good if the ad unit is going to show right next to the image, or it will close some important part of the text.

HOW TO INSERT ADVERTISEMENTS IN THE ARTICLE WITHOUT PLUGINS

Task – Insert Adsense ad units into article body.

Conditions – Use only standard WordPress tools, without the help of plugins.

An important point – the possibility to quickly edit the parameters of the ad block, in all the articles where it is placed.

INSERT ADVERTISEMENT WITH THE SUPPORT OF FUNCTIONS AND SHORT CODES OF  WORDPRESS

First, we need to create a function to display a certain ad unit. And then we’ll create a short code (Shortcodes) in order to be able to quickly insert an ad unit into the right place for us. For example, the body of the article.

The advantage of this method lies in the fact that, if necessary, you can always edit or replace the general code of the ad unit in the function. At the same time, the content of the ad itself will change in all places where it has been inserted through short codes of WordPress.

Perhaps everything that is written above sounds complicated and unclear. However, I think, in fact, everything is very simple and clear. The main thing is to carefully follow all the steps and not forget anything.

WE CREATE A FUNCTION

Let’s create a function ( function) , which will show our contextual advertising. The function can be created directly in notebook. But I would recommend using Notepad2. It is convenient because it shows not only the text, but it shows the correct code. Function will be as follows:

Function anuncio_context ()
{
Return 'Adsens' code;
}

Where “ad_context” – is the name of the function. You can put another name. This does not affect functionality. And instead of the “Google AdSense” line, we need to insert the GoogleAdsense ad unit code. At the end the code will be similar to the following:

Function anuncio_context ()
{
Return '<script async src = "// pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"> </ script>
<! - Advertising ->
<Ins class = "adsbygoogle"
Style = "display: block"
Data-ad-client = "ca-pub-xxxxxxxxxxxxxx"
Data-ad-slot = "xxxxxxxxxxxx"
Data-ad-format = "auto"> </ ins>
<Script>
(Adsbygoogle = window.adsbygoogle || []) push ({});
</ Script> ';
}

Now we have to add a shortcode to our function. It is necessary that we free of problems and have the possibility to put a block of ads in any part of the article. Where we paste this code will show the ad. That is all.

Add_shortcode ('adsense', 'advert_context')

Where ‘adsense’ – this is the short code.

Function adsense_context ()
{
Return '<script async src = "// pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"> </ script>
<! - Advertising ->
<Ins class = "adsbygoogle"
Style = "display: block"
Data-ad-client = "ca-pub-xxxxxxxxxxxxxxxx"
Data-ad-slot = "xxxxxxxxxxxx"
Data-ad-format = "auto"> </ ins>
<Script>
(Adsbygoogle = window.adsbygoogle || []) push ({});
</ Script> ';
}
Add_shortcode ('adsense', 'advert_context')

HOW TO INSERT ADS WITHOUT PLUGINS – FINAL STEP.

Now we have to insert our function into function.php file  of your web that is in Tema folder.

Ojo: best download this file from the server and make a backup. If something goes wrong, you can always load the older version of function.php .

Download the file. We open. And we put our function code anywhere between the tags (<? Php) and (?>), Like this:

Function jrc_noindex_attachment_pages () {
If (get_post_mime_type ()! = False) {
Echo '<meta name = "robots" content = "noindex, nofollow" />';
}
}
Function anuncio_context ()
{
Return '<script async src = "// pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"> </ script>
<! - Advertising ->
<Ins class = "adsbygoogle"
Style = "display: block"
Date-ad-client = "ca-pub-xxxxxxxxxxxxxxxxxx"
Data-ad-slot = "xxxxxxxxxxxx"
Data-ad-format = "auto"> </ ins>
<Script>
(Adsbygoogle = window.adsbygoogle || []) push ({});
</ Script> ';
}
Add_shortcode ('adsense', 'vstavka_context')
?>

Actually, everything. We have created an ad unit output function. Now we just have to insert the short code in the right place in the body of the article. It is simple. Directly on the WordPress blog console. The short code can be added in HTML or through the visual text editor.

To insert an ad unit, you have to choose a suitable place in the article and insert the special keyword. In my case, it’s [adsense] (Google advertising).

If you liked insert ads without plugins article, then please subscribe to our WebStaffs.com Blog. You can also find us on Twitter , Facebook LinkedIn , Google+ and Tumblr.

Be the first to comment

Leave a Reply

Your email address will not be published.


*