I am using this code to put adsense code in the exact middle of the post’s content. But if there is an image there, either the image doesn’t show or both the image and the adsense code don’t show and I get part of a broken html code showing in the middle of the post. Is there a way to use the same code but if there is an image or an
<a>tag in the middle to get the adsense to show after them?
hope someone can help. Thanks!
<?php $content = apply_filters('the_content', $post->post_content); $content = explode(' ', $content); $halfway_mark = ceil(count($content) / 2); $first_half_content = implode(' ', array_slice($content, 0, $halfway_mark)); $second_half_content = implode(' ', array_slice($content, $halfway_mark)); echo $first_half_content.'...'; echo 'Your adsense code'; echo $second_half_content; ?>
- The topic ‘Ads in the middle of post content’ is closed to new replies.