Created
May 19, 2014 14:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have any improvements to this code, feel free to submit them!