Check if the post is older than X days before placing ads


BBAds are part of our life on Internet nowadays and many webmasters use them to make money.

It became common, for me at least, to land on a page 'littered' with ads, and I instinctively bounce off although the content might have been good.

I already posted my opinion on why you should keep your homepage ad-free and here is another tip for how to keep your articles appear ad-free to new visitors.

If you decide to show ads (context, in-text and other) only on articles that are older than xx days (xx being anything from 2 to 5 days) your revenue change only slightly, but you will gain a positive effect on all of the below:

  1. Bounce rate
  2. RSS subscribers
  3. Any social media promotion
  4. Overall credibility of the site

Let's see how can you do that easily if you use WordPress.

Here is a short code you can place in your functions.php file.

function new_post($days = 5) {
	global $post;	
	if(is_single() || is_page()) {				
		$expire = time() - $days*24*60*60;				
		if (mysql2date("U", $post->post_date) > $expire) {		
			$return = true;
		}else{
			$return = false;
		}
	}else{
		$return = false;
	}
	return $return;
}

Now, whenever you add ads, you can perform this check:

<?php if (!new_post(3)) : ?>
 
<!-- your ad code goes here -->
 
<?php endif; ?>

And voila! The ads will appear only on posts that are older than 3 days.


Suggested reading:


Posted in: Startups, WordPress
TAGS:, , , , , , , , , , ,
leave a comment.

Comments:

One Comment

  1. Ainhoa
    Jun 26th, 2012

    I love this simple code, but as you can modify to tell if you have less than 3 days show this one.
    No programming, could you clarify me. thanks

Have your say

Your email is never published nor shared. Required fields are marked *

*
*

Subscribe without commenting

About

vladimir prelovac Vladimir Prelovac is CEO of Prelovac Media, a computer engineer by profession and an adventurer by state of mind. more +


"I would love to change the world, I just don't have the source code yet."

Services

Manage multiple WordPress sites

Built for WordPress enthusiasts, ManageWP helps you manage all your WordPress sites from one central location.

Books

WordPress Plugin Devleopment Book Read my book WordPress Plugin Development: Beginner's Guide

Published by Packt Publishing, available online through Amazon.