Manually adding AdSense to WordPress posts is a relatively simple task that can be accomplished within just a couple of minutes. In this tutorial, we cover the process of adding the code to the singlepost.php. This will allow us to display advertisements on every post only when the post is individually viewed. There are many places within the singlepost.php to add the code, for the sake of simplicity, we are going to cover the hotspot.
Adding Google Ads to WordPress Posts:
- Login to your AdSense account and create a new AdSense code. I used a 336X280 format
- Login to your WordPress Administration panel
- From the navmenu click Appearance > Editor
- From the Theme Files section, select Single Post (single.php)
- Within the theme editor window, scroll down to where it says <div class=”entrytext”>
- Directly below <div class=”entrytext”> add your AdSense code from step 1
- Click the Update file button and go view your site!
(Optional) You can surround the code with <div></div> tags. This will allow us to position the advertisment where we want it. See the example code below.
Left side placement example:
google_ad_client = “pub-1234567890”;
google_ad_slot = “1234567890”;
google_ad_width = 336;
google_ad_height = 280;
If you want the Google ad to float right, change float:left to float:right. If you don’t want to position the code left or right just surround your code with the <div></div> tags