TechTipsApp

Technology tips blog

  • Articles
    Categories
    • Tech news
    • Internet
    • Social Network
    • Google
    • Geeky Tips
    • Android
    • Windows 10
    Top Posts
    • Install Windows XP from USB
    • Install Windows 7 from USB
    • Open Facebook When It's Blocked
    • Partition Hard Drive Without Formatting
    • Reset Windows 7 Password
    • About
    • Contact
    • Privacy policy
    • Advertise
    • Terms of Conduct & Copyright Policy

How to Display Ads Only on Older Posts in WordPress Blog

Tanmay WordPress Leave a Comment

Advertisement is the best and easy way to monetize your blog. Google Adsense, Chitika, Infolinks and many advertisement programs are available to earn some bulks. But too many ads on your blog may play a negative role. Readers do not like too many advertisements when reading a page as the content becomes bit distracted. So, why would you loss your loyalty for some extra penny?
The better thing you could follow and would be a good idea to hide your ads by Google or other ad providers from the newer posts, so that your regular readers can’t see them when reading the latest articles. In this article, I’ll describe the procedure to display ads only on those article which are older than a certain days or months. Before starting, I must say that there are some good WordPress plugins like Who Sees Ads, Adsense Manager, Adsense Deluxe etc. But I do not like to use plugin for those very purpose that can be easily achieved by adding some lines of code.

Display Adsense ads or other advertisements on the Older posts in WordPress

1. Adding the code to Functions.php
Add the following code into your theme’s functions.php file.

 function is_older_post($post_id=null){
 $older_than = 30; global $wp_query;
 if(is_single() || is_page()) {
 if(!$post_id) {
 $post_id = $wp_query->post->ID;
 }
 $current_date = time();
 $offset = $older_than *60*60*24;
 $post_id = get_post($post_id);
 $post_date = mysql2date('U',$post_id->post_date);
 $cunning_math = $post_date + $offset;
 $test = $current_date - $cunning_math;
 if($test > 0){ $return = true; }
 else{
 $return = false;
 }
 }
 else{
 $return = false;
 }
 return $return;
 } 

[Thanks Jean-Baptiste Jung]
Note:
1. The code resides between  ‘<? php’ and ‘?>’ .
2. In second line, set the value of $older_than as your preference. Here the value is 30 to show ads on the posts that are older than 30 days. 3. Save the function.php file.
2. Placing the Ad code
Now put the following code wherever you want to show your ads.

 <?php if(is_older_post()){ ?> Put your Ad code here <?php } ?>

This tricks can be applied for both the banner ads like Adsense, Chitika and the text ads like Infolinks, Kontera etc. Just put the JavaScript code of the ad unit at the specified place. The function is_older_post() will check the post or page if that is older than your specified days. If so then it allows to execute the ad scripts, otherwise the scripts will be skipped. Currently, I’m using this method in this blog. What about you? Let me know.

Post Tags: Blog, Tutorial
Similar Articles from This Blog
How to Add Pictures as Bullets in Microsoft Word
How to Add Pictures as Bullets in Microsoft Word
Install Contact Page in WordPress Blog Without Any Plugin
Install Contact Page in WordPress Blog Without Any Plugin
How to Apply Multiple Formats in Bulk in Word, Excel 2013
How to Apply Multiple Formats in Bulk in Word, Excel 2013
Different Ways To Boot Windows 8 Into Safe Mode
Different Ways To Boot Windows 8 Into Safe Mode
Backup Windows Live Writer Local Draft As You Type In Clouds
Backup Windows Live Writer Local Draft As You Type In Clouds
How to Solve Paint Cannot Save This File Problem in Windows 7
How to Solve Paint Cannot Save This File Problem in Windows 7

Comments

  1. Imran@TechiesBlog :

    Hi Tanmay,
    Very Tutorial sure I will try in my non thesis blog. Moreover your blog looks more clean and refined.
    Thanks for Sharing
    -Imran

    Reply
  2. Tanmay :

    Thanks Imran. You can also apply this in your thesis theme. I’m glad that you liked the new look of my site. This will inspire me. Thanks.

    Reply
  3. Chadrack :

    Thanks for this great tip. I’ve just implemented it on my blog and it worked fine.

    Reply
  4. Tanmay :

    Glad that you find this useful. Keep reading our tutorials.

    Reply
  5. Remond :

    Apply for an urgent money support to your plan, in this finance we offer in low percentage Fast N’ Easy service world wide.offering funds in this company your confortibility is our proud do you have a bad record, have the bank reject you, and nobody willing to lend you money for your plan support contact us today via financeinvesmentservice@gmail.com for more details.

    Reply

Leave a Comment Cancel reply

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

About Us

Tech Tips App is a technology blog, looking forward to broaden the mental horizons of technical geeks round the web. Striving hard to quench your technical thirst, we have put our best efforts on the line of exhaust to satisfy your versatile technical vocabulary.

Recently Published

  1. Partitioning Hard Drive in Windows 7 Without Formatting
  2. How to Find My Contacts on Google Map
  3. Introducing SMS Organizer by Microsoft is the Best SMS App
  4. How to Fix Windows Update When It Gets Stuck
  5. How to Get Rid of Windows 10 Automatic Repair Loop [Solved]
  6. Best Antivirus for Windows 10 (Is Windows Defender Good Enough?)
  7. Best Facebook Messenger Bots to Get more out of Messenger
  8. How to Fax a Document From Your Smartphone
  9. Top Social Media Platforms You Should Always Know About
  10. Bitcoin vs Altcoin: Where to Invest? – Guide For Dummies

© 2021 Tech Tips App All Rights Reserved  Post Sitemap