Show Ads Based on Content Length
Filed in: Make Money Online, WordPress — February 17th, 2007
Problem: Currently I am displaying two blocks of ads on each blog post, one at the top of post, the other at the end of post.
The ad placement is ok but it becomes a problem when I have short posts, which looks like a full page of ads with hidden content. I want to selectively show second ad block only if content is more than 100 words.
By referring to a word count code on WordPress Support, I managed to hide second ad block if content is less than 100 words.
Here is the code. It is for WordPress only. Add the following code after "the_content" function in the "single.php" of your WordPress theme.
-
<?php
-
$countpost = $post->post_content;
-
if ($words> 100) {
-
?>
-
<!-- YOUR AD CODE HERE-->
-
<?php } ?>
My two cents
This is a simple WordPress hack. I hope you find it useful to have more flexible control on ad placements.


