June 11, 2014

How To Paste Adsense Code Below Post Title Single Post Of WordPress

|
The other day I had problem adding Adsense code below the post title for one of my WordPress blog.

I am using the PR News theme and I did not know where to place the code in the single php.

There are some other WordPress themes, where all you need to do is just paste the code right after the <div class="entry">.

Then I read somewhere where it suggests that I create a new php page with Adsense code and then have it called at the single php.

But it didn't seem to work properly.

Then I found an easier method.

Just paste the add the Adsense code in the functions php.

1. Log into  WordPress account.

2. Go to the functions php.

3. Copy the code below:

add_filter( 'the_content', 'wpsnpy_add_single_adsense_code', 20 );
function wpsnpy_add_single_adsense_code($content) {
    if ( is_single() ) 
  echo '
       
PASTE ADSENSE CODE HERE
    ';
    return $content;
}
4. Paste the above set of code just before the the closing tag ?>.

5. Click Update File button.

That's all you need to do to add Adsense or even other ad code below the blog post title for WordPress.

Note: Functions.php is a very sensitive template. If you accidentally paste the code wrongly in there, it can give you a big headache.

You could be locked out of your own site (you cannot both log in or log out) and in addition, your site cannot be accessed.

If it happens to you, then read this post on how to fix functions.php error.