Archives for 

ads posts older

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

3975973661 4cdcba6263 m Check if the post is older than X days before placing adsAds 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.

Related Articles: