Created
December 29, 2012 05:53
-
-
Save ryanriatno/4404803 to your computer and use it in GitHub Desktop.
Insert Ads inside Post Content
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 | |
| add_filter('the_content', 'rr_add_ad_inside_post'); | |
| function rr_add_ad_inside_post($content) { | |
| if ( is_single() ) { | |
| $paragraphAfter= 3; //display after the first paragraph | |
| $content = explode("", $content); | |
| for ($i = 0; $i <count ($content); $i++ ) { | |
| if ($i == $paragraphAfter) { ?> | |
| <p class="alignleft"> | |
| <script type="text/javascript"><!-- | |
| google_ad_client = "pub-xxxxxxxxxx"; | |
| /* 250x250, created 9/10/11 */ | |
| google_ad_slot = "xxxxxxxxx"; | |
| google_ad_width = 250; | |
| google_ad_height = 250; | |
| //--> | |
| </script> | |
| <script type="text/javascript" | |
| src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> | |
| </script> | |
| </p> | |
| <?php } | |
| echo $content[$i] . "</p>"; | |
| } | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment