Skip to content

Instantly share code, notes, and snippets.

@nhatdongnguyen
Created March 7, 2015 06:13
Show Gist options
  • Save nhatdongnguyen/fa0cb5326ff711cd0351 to your computer and use it in GitHub Desktop.
Save nhatdongnguyen/fa0cb5326ff711cd0351 to your computer and use it in GitHub Desktop.
<?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