Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Insert ads after second and fifth paragraph of single post content and after the post content. Provided by Bloggingdude.com:
- add_filter( 'the_content', 'prefix_insert_post_ads' );
- function prefix_insert_post_ads( $content ) {
- $ad_code = '<div> <div class="td-all-devices"><a href="#" target="_blank"><img src="http://localhost/spitzu/wp-content/uploads/2018/06/newspaper-rec728.jpg"/></a></div></div>';
- if ( is_single() && ! is_admin() ) {
- return prefix_insert_after_paragraph( $ad_code, 3, $content ); }
- return $content; }
- add_filter( 'the_content', 'prefix_insert_post_adsNew');
- function prefix_insert_post_adsNew( $content ) {
- $ad_codenew = '<div> <div class="td-all-devices"><a href="#" target="_blank"><img src="http://localhost/spitzu/wp-content/uploads/2018/06/newspaper-rec728.jpg"/></a></div></div>';
- if ( is_single() && ! is_admin() ) {
- return prefix_insert_after_paragraph( $ad_codenew, 6, $content ); }
- return $content; }
- function prefix_insert_post_ads_New( $content ) {
- $ad_codenew = '<div> <div class="td-all-devices"><a href="#" target="_blank"><img src="http://localhost/spitzu/wp-content/uploads/2018/06/newspaper-rec728.jpg"/></a></div></div>';
- if ( is_single() && ! is_admin() ) {
- return prefix_insert_after_paragraph( $ad_codenew, 9, $content ); }
- return $content; }
- add_filter( 'the_content', 'prefix_insert_post_ads_New');
- // 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 ); }
- // Add signature or ad after post content. Provided by Bloggingdude.com:
- function custom_content_after_post($content){ if (is_single()) {
- $content .= '<div> Adsense/Ad code goes here</div>'; }
- return $content; }
- add_filter( "the_content", "custom_content_after_post" );
Advertisement
Add Comment
Please, Sign In to add comment