[WordPress] Display ads after first paragraph only for visited from Google

if ($_SERVER['HTTP_REFERER']=="https://www.google.com/" OR parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)=="www.google.com") { $show_after_p = 2; $content = apply_filters('the_content', $post->post_content); if(substr_count($content, '<p>') > $show_after_p) { $contents = explode("</p>", $content); $p_count = 2; foreach($contents as $content) { echo $content; if($p_count == $show_after_p) { ?> ADS <?php } echo "</p>"; $p_count++; } } } else { the_content(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.