Skip to content

Instantly share code, notes, and snippets.

@nhatdong
Created April 15, 2016 03:44
Show Gist options
  • Select an option

  • Save nhatdong/7716e55ec29ec68c4f203d62bfd6bb61 to your computer and use it in GitHub Desktop.

Select an option

Save nhatdong/7716e55ec29ec68c4f203d62bfd6bb61 to your computer and use it in GitHub Desktop.
Ads added above last paragraph
<?php
function ads_added_above_last_p($text) {
if( is_single() ) :
$ads_text = '<div class="a" style="text-align: center;">[PUT SHORTCODE HERE]</div>';
if($pos1 = strpos($text, '<p>', strpos($text, '<p>') + 3)){
$text1 = substr($text, 0, $pos1);
$text2 = substr($text, $pos1);
$text = $text1 . $ads_text . $text2;
}
endif;
return $text;
}
add_filter('the_content', 'ads_added_above_last_p');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment