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:







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


More like this:


Posted in: Business, WordPress
TAGS:, , , , , , , , , , ,
Both comments and trackbacks are currently closed.

One Comment

  1. Jun 26th, 2012 6:31 PM

    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