Simple Plugin to Inject Ad Code within Blog Post
There are a lot of plugin to inject ad code within blog post out there, but most of them is packed with many features that I don’t really need.
If you like me, just need a simple code to inject the ad code inside the blog post in random position, you can use the following code to achieve that.
You can add the code within your template function.php or download the plugin version here.
<?php
function pk_adsense_injection($content){
if (is_single()){
$adsense_code = '<div class="adcontainer">PUT YOUR AD CODE HERE</div>';
$paragraphs = explode('</p>',$content);
$i = mt_rand(1, count($paragraphs)-1);
$ix = 1;
foreach($paragraphs as $p) {
$temp .= $p;
if ($ix == $i)
$temp .= $adsense_code;
$ix += 1;
}
$content = $temp;
}
return $content;
}
add_filter('the_content','pk_adsense_injection');
?>
Please do not forget to replace ‘PUT YOUR AD CODE HERE’ with your ad code (adsense, adbrite, clickbank etc).
Incoming search engine terms: exclusive wordpress, how to add adbrite code to wordpress com, How to Put Adbrite code on Your Wordpress Blog, inject easy, replace code posts wordpress, where do i put adbrite code in wordpress, wordpress plugin inject content
“Simple Plugin to Inject Ad Code within Blog Post”