Created
April 15, 2016 03:44
-
-
Save nhatdong/7716e55ec29ec68c4f203d62bfd6bb61 to your computer and use it in GitHub Desktop.
Ads added above last paragraph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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