Well? Do you hard code your ads or do you use a sophisticated ad management plug-in?
I don't do either. Here's what I do to manage ads throughout a website. As every other solution, this is simple and resource efficient as well.
1. I create a directory to store text files, let's call it ads. Then put an Adsense piece of code in a text file in that folder and name the file ad1.txt and create another one ad2.txt.
<?php
function printAd($name) {
$adsdir='ads';
return file_get_contents($adsdir.'/'.$name.'.txt');
}
function adSearch($text) {
$s='/\[ad=(.*?)\]/e';
$r='printAd("$1")';
return preg_replace($s,$r,$text);
}
// test
$post='<p>[ad=ad1] This is a post, which contains an ad.</p>';
$post.='<p>Different ad in the second paragraph [ad=ad2]</p>';
echo adSearch($post);
?>
This quick snippet allows you to easily manage all of your adsense ads in your posts. Additionally, if you want to place an ad in every post automatically, you can always do it by calling printAd() before you parse the post's body.
marketing, php, adsense, advertising
If you liked the article and want to contribute to it, please feel free to leave your comment. HTML tags are not allowed, but you can use the following BBCode to enhance your message: [url] [quote] [code] [b] [i] [u] [color].