How to Insert Ads on Left or Right Side of Post content


How to Insert Ads on Left or Right Side of Post content

Recently one our Blog Visitors ask me About Best Ad’s Placement for WordPress website for Increase the Ad revenue after that I conduct a Small Poll on Hellboundbloggers Facebook Group Most of them Recommends me to Insert Ads on Left or Right Side of Post content in WordPress(First Paragraph).Some SEO Experts Says it will Help to increase CTR (click-through-rate) I am also seen on Pro’s Blog They Placed the ad on Left or Right Side of the WordPress Post content or center of the Post content Most of the WordPress themes comes with Below post title and Below Content Ad placement option But we need to display an Insert Ads on Left or Right Side of Post content(First Paragraph) in WordPress.Follow Our Below Step to Insert Ads Within  Left or Right Side of WordPress Post content Without plugins.

Follow Our Below Step to Insert Ads Within  Left or Right Side of WordPress Post content Without plugins.

Here is the Simple PHP Code for you in My past I mention this lines Everytime Trusting Plugin is a bad Idea there are lot of plugin for this in WordPress plugin Market But I Request to Insert Ads to Left or Right of WordPress post Content Without plugins 🙂

Insert Ads on Left or Right Side of Post content

  • Login into Your WordPress Dashboard
  • Paste this Below CSS Code on your WordPress theme Stylesheet or Follow this Method add a Custom CSS on WordPress

.awts_ad_right{
float:right;
margin:18px;
}
.awts_ad_left{
float:left;
margin:18px;
}

//Insert ads.

add_filter( 'the_content', 'awts_post_ads' );

function awts_post_ads( $content ) {
 
 $ad_code = '<div class="awts_ad_right">Your Ad Code</div>';

if ( is_single() && ! is_admin() ) {
 return awts_insert_post_ads( $ad_code, 1, $content );
 }
 
 return $content;
}
 
// Parent Function that makes the magic happen
 
function awts_insert_post_ads( $insertion, $paragraph_id, $content ) {
 $closing_p = '</p>';
 $paragraphs = explode( $closing_p, $content );
 foreach ($paragraphs as $index => $paragraph) {

if ( trim( $paragraph ) ) {
 $paragraphs[$index] .= $closing_p;
 }

if ( $paragraph_id == $index + 1 ) {
 $paragraphs[$index] .= $insertion;
 }
 }
 
 return implode( '', $paragraphs );
}
  • To change the Ad Placement Replace awts_ad_right CSS Class For Right side awts_ad_right For Left Side awts_ad_Left.
  • Replace Your Ad Code with your Ad Code or Affiliate Banner Codes
  • That’s all Successfully we Insert Ads on Left or Right Side of Post content.

Hope this Article Help you to Insert an Ads on Right or Left Side of the WordPress Post Content.if you have any doubts Feel free to comment here our Team will help you.

Also Read



Was this article helpful?
Thanks!

Your feedback helps us improve Allwebtuts.com