Using wordpress filters, we can insert ads (or any content you wish) within the post content. Filters are great way to modify a content. They take one input, apply the modifications and return the output. That’s what we are going to do now for your post content. We are going to put a place holder for ads in our post content and using filters we are going to replace this placeholder with Adsense.
Follow these steps:
- Get your Adsense code.
- Open functions.php or custom_functions.php (if you are using Thesis theme) in your wordpress dashboard and add the below code (take a backup before, if you like):
function insertAdInPost($post_content){ $ad='[your-Ad]'; return str_replace("[adsense]", $ad, $post_content); } add_filter("the_content", "insertAdInPost");
- Replace the place holder “[Your-Ad]” with your adsense code and save the file.
- Edit any post in which you want to add Adsense, and place the markup “[adsense]” where you want to insert the ad.