How to Insert Adsense Inside WordPress Post Without Plugin

Posted 21 May By Leandro Riccini MargarucciIn Blog List, How-to, WordPress Guide0 comments

"Today, I'm going to show you how to insert a Google Adsense script inside your WordPress blog post without to install plugin."

If you decided to earn a little bit of extra money with your WordPress blog or website inserting the Google AdSense ads, here you can find a way to add them without to install plugins.

There are many plugins to easily insert your AdSense banners but, plugins weigh and take up memory until negatively compromising the website performance in terms of loading speed and user experience. That’s why I prefer to substitute them with a bit of code lines.

First, you need to open your functions.php file and insert the insert_post_ads function, as you can see below. You can use any text editor or IDE that you like. Notepad is fine too, but I used Sublime Text.

After inserting the function, you need to past your Google AdSense script between <div></div> tags, as you can see in the code above. Once installed, it will be displayed at the second article paragraph, because it is already set up in this way.

Obviously, we can change the statement every time we want. Just edit the number 2 that you can see in the return statement called insert_after_paragraph.

Then you need to add another function (see below), always in the functions.php file, called insert_after_paragraph.

That’s how you can insert your AdSense code in just few steps. If you know another right way to insert Google AdSense ads between article paragraphs, you can write it in the comments below. I’ll be happy to share it. Keep on coding in PHP!

No Comments (0)

Leave a Comment

 Previous  All works Next