Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/5277191 to your computer and use it in GitHub Desktop.
Save braddalton/5277191 to your computer and use it in GitHub Desktop.
Change the 007 to your category i.d
/**
* @author Brad Dalton - WP Sites
*
* @link http://wpsites.net/web-design/ads-specific-paragraph-single-posts/
*/
add_filter( 'the_content', 'wpsites_adsense_middle_content' );
function wpsites_adsense_middle_content( $content ) {
if( is_single() && in_category ('7') )
return $content;
$paragraphAfter = 1; //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