Created
March 7, 2015 06:13
-
-
Save nhatdongnguyen/fa0cb5326ff711cd0351 to your computer and use it in GitHub Desktop.
This file contains 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', 'sp_adsense_first_paragraph' ); | |
function sp_adsense_first_paragraph ( $content ) { | |
if ( !is_single() ) | |
return $content; | |
$paragraphAfter = 2; //Enter paragraph number | |
$content = explode ( "</p>", $content ); | |
$new_content = ''; | |
for ( $i = 0; $i < count ( $content ); $i ++ ) { | |
if ( $i == $paragraphAfter ) { | |
$new_content .= '<div style="width: 600px; height: 100px; padding: 5px 5px 5px 0; margin-right: 0;">'; | |
$new_content .= 'Paste Adsense Code Here'; | |
$new_content .= '</div>'; | |
} | |
$new_content .= $content[$i] . "</p>"; | |
} | |
return $new_content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment