Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Insert ads code into post content
- * $adsCode: Specify code that wants to add
- * $insertAfter: Specify paragraph number
- */
- add_filter('the_content', 'cw_insert_post_ads');
- function cw_insert_post_ads($content){
- if(is_single()){
- //ads code
- $adsCode = '<div>Insert your ads code here</div>';
- //insert after
- $insertAfter = 2;
- $closingP = '</p>';
- $contentBlock = explode($closingP, $content);
- foreach($contentBlock as $key => $con){
- if(trim($con)) {
- $contentBlock[$key] .= $closingP;
- }
- if(($key + 1) == $insertAfter){
- $contentBlock[$key] .= $adsCode;
- }
- }
- $content = implode('', $contentBlock);
- }
- return $content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement