Skip to content

Instantly share code, notes, and snippets.

@cdevroe
Created May 19, 2014 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdevroe/e99a2c8faa175b9c327e to your computer and use it in GitHub Desktop.
Save cdevroe/e99a2c8faa175b9c327e to your computer and use it in GitHub Desktop.
Only show Google Ads on Posts older than 14 days from published date on Barley CMS
if ( $('[id$=_published_on]').length > 0 ) {
var publishedOn = new Date( $('[id$=_published_on]').html() );
var secondsSincePublished = Math.floor( (new Date() - publishedOn) / 1000 );
var daysSincePublished = Math.floor( secondsSincePublished / 86400 );
if ( daysSincePublished > 14 ) {
console.log('It has been '+daysSincePublished+' days since this post was published so we are going to show a Google Ad.');
(adsbygoogle = window.adsbygoogle || []).push({});
} else {
console.log('It has only been '+daysSincePublished+' days since this post was published so we are not going to show a Google Ad.');
}
}
@cdevroe
Copy link
Author

cdevroe commented May 19, 2014

If you have any improvements to this code, feel free to submit them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment