Last updated on December 15, 2009. Tags: ads placement, Adsense, Chitika, dynamic page, thank you page, user agreement, WordPress search
Adsense and Chitika are two of the most popular ad provider that can be used in monetizing your website. While they have different policies in using their ads (as stated in their respective user agreements), they have rules that are the same in essence if not in words. One of these rules: You're not supposed to put ad units in any page with no content.
The user agreement of Chitika states the following:
Paid Listings must not be displayed on any domain parking websites, pop-ups, pop-unders, error, registration, or "thank you" pages, or in any email.
The user agreement of Google Adsense mentions practically the same thing:
Google ads, search boxes or search results may not be... Placed on any non-content-based page.
Google's policies on ad placement were provided in the form of bullet list and the ellipsis indicate that there are other items in the list before the one that specifically mentioned the non-content-based pages.
You can easily follow these policies if your website is made of HTML files. You can simply insert the ad codes in pages with content and not insert them on pages without content, but what if you are using WordPress? The different parts of the pages are generated from the PHP files of the theme and thus you cannot manually determine which page gets the ads and which page don't.1
In essense, these policies tell us that we're not suppose to put ad units in pages that have no content. Some of these pages are:
One way of ensuring that you ads will appear only in pages with content is to put the ad codes in the theme files single.php and page.php to put them in the posts and static pages respectively. An ideal location is to put your ad unit before or after (or both) the main content. You can do this by pasting the ad codes before and/or after the line <?php the_content(); ?>.
If you use your website primarily as blog and your static pages are very few, and some of these are the contact form, "thank you" and error pages, it's advisable that you insert the ad codes in the single.php only.
You can also insert ad units between two paragraphs as I discussed in my previous post.
In some cases, it is ideal to put the ad units in the common elements of the site. The header and the sidebar are particularly suitable for ads because the site visitors see these parts often. You might also want to put ad units in the footer but it's the least noticeable part of the site and any ad unit you put there will not be that prominent.
To include ad units in these common elements without violating the policy against non-content pages, locate the part where you want to insert the ad code and paste the following PHP codes:
<?php if ( is_page(11) || is_page(22) || is_page(33)) : ?> <!--display no ads--> <?php elseif ( is_search() || is_archive() || is_page() || is_single() || is_category() || is_tag() || is_home() ) : ?> <!--insert ad code here ads--> <?php else : ?> <!--display no ads--> <?php endif; ?>
You can then insert the ad code in the line marked by <!--insert ad code here ads-->.
The first line indicates specific pages where you would not want the ad unit to appear such as the contact form, the "thank you" page and the error page. Simply replace the numbers in the parentheses (11, 22 and 33) with the IDs of the pages that are not suppose to have ads. You can have less than or more than 3 pages in the first line as long as every two adjacent is_page(n) is separated by OR argument ||.
The third line indicates all the dynamic page type where the ad codes should appear in the following order: search results, archive, static pages (except for those specified in the first line), posts, category pages, tag pages and home page (list of posts option). Since these are all the dynamic pages that WordPress can generate, the <?php else : ?> in the fifth line covers only one type of dynamic page, the "not found" page. The fifth line basically indicates that there will be no ad units in any "not found" page.
The search results is particularly tricky because whether it will count as non-content or not depend on the keywords being searched. If there's a match, then it has content. If there's no match ("no results" page), then it is non-content. So far, I do not know any way of separating the "no results" from the "search results with match found" (please let me know if there's any).
Here in Codeleet as well as in my other blogs, the ad units still appear in "no results." My reasoning is that these pages are not permanent and not indexed by searched engines (unless someone put up a hyperlink to the dynamic URL, but there's no logic in doing that). Once the person using the search function click the back button of his or her browser, that particular page disappear.
However, if you want to be really sure that no ad unit will appear in any non-content page including the "no result" page, I suggest you just remove the ad in any search result page including those with match found. You can do this by deleting the is_search() and the OR argument (||) immediately after it in the third line.
I am citing Chitika and Adsense as examples because they are the ones that I use in my blogs. I am not sure if other ad networks like Bidvertiser or Yahoo Publiher Network (YPN) also have similar policy. If they do, you can also use this technique to prevent their ad units from appearing in non-content pages.
Footnote:
Posted by Greten on October 14, 2009 under WordPress tweaks
Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.
* Required. Your email will never be displayed in public.