You might want to put the ads within your post content in WordPress blog. Or you may see the blog with ads inside their content. Hopefully, you don’t write it on the content. If you want to include ads in your post, here is we will show you how to insert ads without activate any plugin or using any the ad management plugins.
It is simply copy the following code below and paste it on your theme’s functions.php. Keep in mind though that the codes could be used to insert ads after second paragraph.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<?php //Ads after second paragraph of single post content. add_filter( 'the_content', 'prefix_insert_post_ads' ); function prefix_insert_post_ads( $content ) { $ad_code = '<div>Ads code goes here</div>'; if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $ad_code, 2, $content ); } return $content; } // Parent Function that makes the magic happen function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); } |
Note:
You have add your ad code on line 9 (it says ‘Ad code goes here’). If you want to change the paragraph number, that’s a simple way by change the number ‘2’ into another paragraph number what you want.