Adding adsense

Adding adsense is pretty easy - copy and paste the code where you want the ads to appear.

If you want a 120*600 skyscraper to appear in your sidebar at the bottom:

<script type=”text/javascript”><!–
google_ad_client = “pub-X”;
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = “120×600_as”;
google_ad_type = “text_image”;
google_ad_channel =”";
//–></script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>

would be copied to this location in the default style sidebar.php:

</ul>
</li>
<?php } ?>
<—–paste it there

</ul>
</div>

You can experiment with various places

If you want the ad right at the top of the whole page:

<body>
<—–paste the code there

<div id=”page”>

If you want the ad at the bottom of your posts:

</div>
<—–paste the code there

<?php get_sidebar(); ?>

The above is all fairly basic.
But what if you wanted an ad to only appear under the first post and nowhere else ?

Open your theme index.php, and find this line:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Immediately above that, paste this:

<?php
$postnum = 1;
$showadsense1 = 1;
?>

That’s part one of the code - the value.

Staying in index.php, scroll down to this part:

<p class=”postmetadata”>Posted in <?php the_category(’, ‘)
?> | <?php edit_post_link(’Edit’, ”, ‘ | ‘);
?> <?php comments_popup_link(’No Comments »’, ‘1
Comment »’, ‘% Comments »’); ?></p>
</div>
<—– Note this gap !
<?php endwhile; ?>

Into that gap, you paste this:

<?php if ($postnum == $showadsense1) {
echo ‘
Your adsense code goes here
‘;
} ?>

<?php $postnum++; ?>

You put ALL your code, plus the bit at either end, into the gap I pointed at.
The ‘value’ is where to show the post. The bottom part checks to see
what the number is and when the number matches, it puts the ad on the
screen. So if you made $showadsense1 = 3; in both locations, the ad would appear only after the 3rd ad.

Want 1 ad after the first post and 2 after the second ?
Copying from above, you would use this instead:

<?php
$postnum = 1;
$showadsense1 = 1;
$showadsense2 = 2;
?>

which would go at the top.

Again copying from the above, you already have this:

<?php if ($postnum == $showadsense1) {
echo ‘
Your adsense code goes here
‘;
} ?>

<?php $postnum++; ?>

and you would add another block below the first ad, but above the counter at the bottom. Here it is all together:

<?php if ($postnum == $showadsense1) {
echo ‘
Your adsense code goes here
‘;
} ?>

<?php if ($postnum == $showadsense2) {
echo ‘
Your adsense code goes here
‘;
} ?>
<?php $postnum++; ?>

The first bit says the values, then the values are checked each time WP goes through The Loop.
If the counter matches what your value is, the ad is shown. Changing the numbers lets you change the placement.

Lastly, maybe you want an ad ONLY when people are looking at a single post.

If you are using the default theme, open single.php (or any theme that
has such a file), put the adsense code right below this line:

<?php the_content(’<p class=”serif”>Read the rest of this entry »</p>’); ?>

If you are not using such a theme, you need different code.
Decide where you want the ad to appear, and paste this code in that location:

<?php
if (is_single()) { echo ‘
Your adsense code goes here
‘;} ?>

You can ads anywhere and make them appear under
certain conditions only. So you could ads just for pages, others in the
sidebar on the home page with different sidebar sizes on archived
posts, no ads at all on the main page but scattered throughout the blog
on other views.
It’s the conditional if (is_single) or if (is_home) and other template tags that you need to play with.

How to Add Ads Between Posts:

1. Log into your WordPress admin panel
2. Select Presentation -> Theme Editor from the navigation menu
3. From the Theme Editor, find and select the “Main index template” (index.php) from the list to the right
4. Find the following line

PHP:

  1. <?php if (have_posts()) : ?>

5. Above it add the following line

PHP:

  1. <?php $count = 1; ?>

6. Now find the following line

PHP:

  1. <div class=“entry”>

7. Add the following code directly below it (replace AdSense Code with your code)

PHP:

  1. <?php if ($count == 1) : ?>
  2. AdSense Code
  3. <?php endif; $count++; ?>

8. Click update file, then go view your site to confirm that the ad has been added to the first post listing.Note: To change which post your ad is placed under, simply change the count numberExample: $count == 2 will place the ad under post 2

——————————————

On the homepage, one of the more effective places to implement Google Adsense is after the first post (same for any other archive type page, like the categories). While the CTR (click through rate) won’t be as high as placing the code above the first post, or after the first post title, it’s much cleaner and will provide a ‘less spammy’ place to put the code. Remember, folks are here for your content - not your ads.

At any rate, it’s pretty simple. You’ll need to use this code to prevent your ad code from appearing after every single post, as Wordpress would just loop and keep showing it (which would likely be against Google’s TOS as they only allow 3 ad blocks per page).

First, open your index.php (or home.php, archive.php, or any other file you want to do this for) and find this line:

<?php if (have_posts())

and before, add:

<?php $count = 1; ?>

This will be used to track which post is being displayed. Next we’re going to add the code to display your Adsense. Find:

<?php the_content

and after, add:

<?php if ($count == 1) : ?>
Adsense Code Goes Here
<?php endif; $count++; ?>

There you have it, quick and dirty. Remember, this has to go inside the loop otherwise it won’t display properly (place it before the <?php endif; ?> which closes the loop. If you wanted this outside the loop (completely before or completely after all your posts), there would be no need to iterate through a post count. You can change this code to display after any number of posts by changing the $count == 1 to whatever post number you’d like.

—————————————-

Looking for a solution of how to put Google Ads in your post and let the text wrap around it? Then you come to the right place. I am going to show you how to implement it for WordPress. Actually it is not as hard as you might think. All you need to do is to download a plug-in from here. Once you downloaded the file; unzipped it. I use FireFTP to upload the unzipped file to this folder /word-content/plugins/. One more thing you need to do before you can use this plug-in. That is you need to edit adsense.php otherwise you can’t earn money because those codes are not yours. Open adsense.php file, search down to the middle, and find the lines of <!– Begin Google Adsense code –> and <!– End Google Adsense code –>. You need to put your Google Ads between these two lines. Make sure you use the following codes to wrap around them. What I mean is your codes should look like the one below:

<!– Begin Google Adsense code –>
<div style=”display:block;float:left;margin: 5px 5px 5px 5px;”>
Your Google Adsense codes go here
</div>
<!– End Google Adsense code –>

You can change to float right, left or center; adjust 5px to meet your needs. By the way margin: 5px 5px 5px 5px represents for top, bottom, left, and right margin spacing respectively. After you made your changes, make sure you save it and upload it back to this folder: /wp-content/plugins/adsense/. Now login to your admin area, click on Plugins on the Menu Bar, and make sure you activate Adsense. You should see a new button, Adsense, on your editor’s Code Button. Now go ahead and try to click on Adsense button and place the ads wherever you want it to be. See mine on this post. Hope you enjoy it like I do! If you are using Google Blogger, check out How to Wrap Your Blogger Post Around Google Ads? and How to Wrap AdSense Ads Around and Inline Beside Blogger Post Content here.