Adding ADS between post contents in WordPress without using any plugins.
Most websites owners need to put their advertisements in different places of their own websites.
They need to put them between post content for visitors.
Follow the coming steps to do this:
- Open your theme folder.
- Open the file named “functions.php” into your code editor.
- Copy & paste the following function code before the closing php tag ?>:
function adsIntoPostContent($content){ if(is_single()){ $content_block = explode('<p>',$content); if(!empty($content_block[2])) { for($i=1;$i<count($content_block);$i++) { $content_block[2] .= 'insert_the_AD_code_here'; } $content = implode('',$content_block); $content_block[$i] = '<p>'.$content_block[$i]; } } return $content; } add_filter('the_content', 'adsIntoPostContent');
- Replace the text string (( insert_the_AD_code_here )) into the function by the actual ad code.
- Save changes.
- Visit a post of your website to see your AD into your post.
Enjoy your advertisements.