How to rotate 2 different custom ads
-
Hello,
I use a custom code to display ads on my site. Basically, it’s a block with a few text ads in it that gets inserted after the nth paragraph of each post.
Is there any way to rotate the ads? What I mean is, when visitors click and visit another post/page, I’d like for a different set of ads to be displayed.
So that way a visitor doesn’t see the same ads no matter what page/post he or she visits.
I am hoping that would help with “ad blindness” and increase conversions and revenue.
Here’s the current code that I am using to display the ad:
// Lets Insert first custom ad after nth paragraph of each post add_filter( 'the_content', 'prefix_insert_first_ad' ); function prefix_insert_first_ad( $content ) { $ad_code = '<div> <div class="custom-ad"> ----MY CUSTOM AD GOES HERE---- </div>'; if ( is_single() && ! is_admin() ) { return prefix_insert_after_paragraph( $ad_code, 6, $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 ); }
Thank you very much in advance.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to rotate 2 different custom ads’ is closed to new replies.