The topic of advertising on a website can be a sensitive one. To some, it is intolerable under any circumstance, to others it’s just another part of the internet experience. I like to think I fall somewhere in between these two extremes. I realize that many site owners work very hard to create quality content and while some do this purely as a labor of love, it is still nice to be able to recoupe some of the time and expense of running their website.
Internet advertising can be something of a mixed bag for the visitor as well, but there is no reason a site can’t feature advertising that is safe, inoffensive and that at least attempts to be related to the topic at hand (such as Google’s Adsense).
The code snippet below attempts to strike a balance between the need for ad revenue and the user experience. It allows the site owner to differ ads from appearing in their WordPress site until after a number of days have passed. This way, faithful readers enjoy an ad-free experience for a period before the any single page or post becomes monetized.
This goes in any of the template files for your theme (single.php, page.php, etc) wherever you want the ad to appear. You can use it multiple times, and change the contents or different ad code. You can further customize the appearing by applying CSS styling to the contents of the time deferring material.
GOOGLE ADSENSE CODE HERE
This next part goes into your THEME’S functions.php file (NOT WordPress core functions.php). The $days = 60; can be set to whatever you like. Two months seemed fair to me.
// Allow advertising on old posts only
* Standard disclaimer here. Before editing any critical files in WordPress you should make a backup and be prepared to roll back any changes in case you run into problems or conflicts. This code is offered with no guarantees or support. Use at your own discretion.
Need help implementing this tip in your WordPress site? Contact us for our professional services. We can also provide support & expertise in convenient “blocks” to suit your short and long term needs.
I'm the front-man of It's WordPress. I come from a diverse array of backgrounds, enjoying the opportunity to expand my knowledge base and skill set by re-inventing myself. I enjoy environments that focus on emerging information, technology and concepts. I put on the technical hat in my early 20s and never really looked back. I'm love technology and the internet, as well as the outdoors and avidly hike, kayak and camp every chance I get.
We can take you from concept, through design, development and deployment in one seamless process. Whether you choose a self-managed web site or need a continuing support relationship; we've got you covered.