Skip to content

Instantly share code, notes, and snippets.

@mcgregormedia
Created March 25, 2015 11:58
Show Gist options
  • Save mcgregormedia/0ac3c80cd00f294e10d8 to your computer and use it in GitHub Desktop.
Save mcgregormedia/0ac3c80cd00f294e10d8 to your computer and use it in GitHub Desktop.
<?php
$required_paragraphs = 3;
$content = apply_filters( 'the_content', $post->post_content );
if( substr_count ( $content, '<p>' ) > $required_paragraphs ){
$contents = explode( "</p>", $content );
$paragraphs = 1;
foreach( $contents as $content ){
echo $content;
if( $paragraphs == $required_paragraphs ){
/* Advert code here */
}
echo "</p>";
$paragraphs++;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment