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 vijujohns/bd843f41fc3e1f5df73d to your computer and use it in GitHub Desktop.
Save vijujohns/bd843f41fc3e1f5df73d to your computer and use it in GitHub Desktop.
Automatically insert Google Adsense ad to the top left or right of each post content http://www.wppicker.com/how-to-insert-ads-to-top-left-right-of-post-content-without-plugins/
//Automatically Insert Google Adsense ads to the top left or right of each post content.
add_filter( 'the_content', 'wpp_insert_ads_to_content' );
function wpp_insert_ads_to_content( $content ) {
$ad_code_wrapper_start = '<div style=”display:block;float:right;margin: 0px 0px 0px 10px;”>';
$ad_code = ' Copy and Paste Ad sense code here. Do not remove the starting and ending single quotes ';
$ad_code_wrapper_end = '</div>';
if ( is_single() && ! is_admin() ) {
$content = $ad_code_wrapper_start.$ad_code.$ad_code_wrapper_end.$content;
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment