Guest User

Untitled

a guest
Jul 24th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. //Insert ads after second and fifth paragraph of single post content and after the post content. Provided by Bloggingdude.com:
  2. add_filter( 'the_content', 'prefix_insert_post_ads' );
  3.  
  4. function prefix_insert_post_ads( $content ) {
  5. $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>';
  6. if ( is_single() && ! is_admin() ) {
  7. return prefix_insert_after_paragraph( $ad_code, 3, $content ); }
  8. return $content; }
  9.  
  10. add_filter( 'the_content', 'prefix_insert_post_adsNew');
  11.  
  12. function prefix_insert_post_adsNew( $content ) {
  13. $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>';
  14. if ( is_single() && ! is_admin() ) {
  15. return prefix_insert_after_paragraph( $ad_codenew, 6, $content ); }
  16. return $content; }
  17.  
  18. function prefix_insert_post_ads_New( $content ) {
  19. $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>';
  20. if ( is_single() && ! is_admin() ) {
  21. return prefix_insert_after_paragraph( $ad_codenew, 9, $content ); }
  22. return $content; }
  23. add_filter( 'the_content', 'prefix_insert_post_ads_New');
  24.  
  25. // Parent Function that makes the magic happen
  26. function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = '</p>'; $paragraphs = explode( $closing_p, $content );
  27. foreach ($paragraphs as $index => $paragraph) {
  28. if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; }
  29. if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $insertion; } }
  30. return implode( '', $paragraphs ); }
  31.  
  32. // Add signature or ad after post content. Provided by Bloggingdude.com:
  33. function custom_content_after_post($content){ if (is_single()) {
  34. $content .= '<div> Adsense/Ad code goes here</div>'; }
  35. return $content; }
  36.  
  37. add_filter( "the_content", "custom_content_after_post" );
Advertisement
Add Comment
Please, Sign In to add comment