Skip to content

Instantly share code, notes, and snippets.

@tomharrigan
Created June 1, 2015 18:06
Show Gist options
  • Save tomharrigan/53772579ccae93cb4884 to your computer and use it in GitHub Desktop.
Save tomharrigan/53772579ccae93cb4884 to your computer and use it in GitHub Desktop.
insert ad in content
function mobile_single_post_ad( $content ) {
if( wp_is_mobile() && is_single() ) {
$limit = 100; //word limit
$contents = explode("</p>", $content);
$words = 0;
$displayed = false;
foreach ($contents as $paragraph) {
$words = $words + str_word_count($paragraph);
echo $paragraph . "</p>";
if( $words >= $limit && $displayed == false ){
$displayed = true;
echo '<div id="mobile-post-ad">'; tdr_ad_widget( 'mobile' ); echo '</div>';
}
}
} else { return $content; }
}
add_action('the_content', 'mobile_single_post_ad');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment