Show your ads on only old posts!
We use Google Adsense or any other ad servers for make money :) You can use this ads on your old posts. I don’t know any pluginfor that function but we can make a function for use ads… Let’s begin…
Here is the code;
To use this code open your functions.php and paste this code into end of file.
function is_old_post($post_id=null){
$days = 15;
global $wp_query;
if(is_single() || is_page()) {
if(!$post_id) {
$post_id = $wp_query->post->ID;
}
$current_date = time();
$offset = $days *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;
}
After that use this code for show your ads…
<?php if(is_old_post()){ ?>
INSERT AD CODE HERE
<?php } ?>
This function show ads on your 15 days old posts. To change this simply change $days value
- Wordpress















Made by Symmetric Web
Distributed by Smashing Magazine
3 Responses
Good tutorial… thanks ..
[...] WpFunc nos ayuda a tener más contentos a nuestros usuarios habituales sin tener que eliminar nuestros anuncios completamente. Este interesante tutorial nos facilita un código con el que podemos mostrar anuncios sólo en post que se hayan publicado con anterioridad en WordPress, pudiendo configurar el número de días de antiguedad que tiene que tener dicho post para mostrarlos. [...]
You’re Welcome!