The free version of the WPTouch Mobile Plugin for WordPress does not allow you to insert Adsense ads in your posts pages.

It’s possible to do it, you have to do the changes directly in the plugin source code, but it’s not that difficult.

I wanted to add Adsense ads before and after my posts, as well as in the middle. Both are explained below.

IMPORTANT: Note that it’s possible that updating the WPTouch Plugin makes you loose this changes.

Adding Adsense add before and after post content in WPTouch

Step 1. Using your favorite File Manage Software (Filezila, WinScp or even the built-in File Manager in your Server Cpanel instalation) , navigate to the wp-content/plugins/wptouch/themes/bauhaus/default directory (if you’re using another theme in WPTouch that’s not bauhaus, you’ll need to navigate to it’s appropriate folder).

Step 2. Open single.php file for edit, and search for “<?php wptouch_the_content(); ?>”

Step 3. Insert the adsense ad code before this line so it appears before the content. Insert after that line so it appears after the content, like this:

How to place adsense in WPTouch
Step 4. Save the file, and check on your mobile. You’ll now have your adsense ads appearing in your articles pages before and after the content (Note that sometimes Adsense needs some minutes so the ads are available and displaying!)

Adding Adsense in the middle of an article/post in WPTouch

Step 1. Using your favorite File Manage Software (Filezila, WinScp or even the built-in File Manager in your Server Cpanel instalation) , navigate to the wp-content/plugins/wptouch/core directory.

Step 2. Open theme.php file for edit, and search for function “wptouch_the_content()”

Step 3. We’ll make some changes to this function to make the ads appear in the middle of the post.

The function will, originally look like this:

wptouch_the_content_originalWe’ll change it to this:

NOTE: You’ll have to replace ####YOUR AD CODE GOES HERE#### with the ad code you retrieve from Adsense. Also, in the ad code you get from Adsense you’ll need to replace all double quotes – “- by a single quote – ‘ -:

function wptouch_the_content()
{
$originalContent = apply_filters('the_content', wptouch_get_content());
$pTotal = substr_count($originalContent, " ");
$pAd = (int)($pTotal / 2);
if ($pTotal == 3) $pAd = 2;
$myContent = "";
$contents = explode(" ", $originalContent);
$pCount = 0;
foreach($contents as $pContent) {
$myContent = $myContent . "" . $pContent;
if ($p_count == $pAd) {
$myContent = $myContent . " ####YOUR AD CODE GOES HERE#### ";
}

$myContent = $myContent . " ";
$p_count++;
}

echo $myContent;
}

In the end it will look like this:

wptouch_the_content_EDITED

Step 4. Save the file, and check on your mobile. You’ll now have your adsense ads appearing in your articles pages in the middle the content (Note that sometimes Adsense needs some minutes so the ads are available and displaying!)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>