Close Menu
My SiteMy Site
  • Home
  • Reviews
  • Computers
  • How Tos
  • Travel & Lifestyle
  • Phone ROMs
  • Contact
    • Advertise
    • About Us
Facebook X (Twitter) Instagram
My SiteMy Site
  • Home
  • Reviews
  • Computers
  • How Tos
  • Travel & Lifestyle
  • Phone ROMs
  • Contact
    • Advertise
    • About Us
My SiteMy Site
Home»Web Design Tips»Wordpress»How To Insert Ads Within Post In WordPress
Wordpress

How To Insert Ads Within Post In WordPress

Oscar FrankBy Oscar Frank3 Mins Read
Share
Facebook Twitter LinkedIn WhatsApp Pinterest Email

Here is a story that prompted me into writing this short tutorial on how to insert any Ad network within your wordpress post content.

how to place ads within content in wordpress after first or second paragraph

I actually decided to tweak my blog a little bit this morning, and what came to my mind was placing an additional unit of Google Adsense Text Ads into my post content. I choose to add the code within my post content after the second paragraph of all my articles, but it wouldn’t have been possible editing about 500 articles just to add the Adsense code into the second paragraph each. I had to make a little research and came up with some snippets that helped me achieve the task.

The most amazing part of my story is after placing the Adsense unit within the post, I had a better CTR and it increased my earnings today.

  • Must Read: How Many Adsense Units Per Page are Allowed
  • How To Insert Adsense Ads Below Post Title In Blogger

Enough of my story, let me give you the code to add any sort of Advert within your post content after the second paragraph. It would place the Ad automatically to all your blog post.

Adding Adsense After Second Paragraph In WordPress Posts

1. Login to your WordPress Dashboard

2. Click on Appearance > Editor on the left side bar.

3. Now click on functions.php on the right side bar of the page that loads, it is the function file of your current theme on your blog.

4. In the very last line of the edit box that just loaded, paste the below code

//Insert ads after second paragraph of single post content by oscarmini.com.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div align="left">Your Ads Code Here</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $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 );
}

5. Then Save.

Remember to replace the place written Your Ads Code Here in the code above to your Adsense or other Ad network code.

  • Must Read: How To Increase Your Adsense Earning

You would be glad you did as this has simply increased my Adsense earnings. I hope you share this article and leave your useful comments.

Ads Placement Tips Adsense Tips wordpress tips

Related Posts

WordPress Blog Hosting made easy with SeekaHost Blog Hosting Control Panel

December 4, 2020

How to Create a Website with Elementor Page Builder in WordPress

April 1, 2019

Top 3 Reasons Backing Up Your Files Offsite Is Extremely Important

February 27, 2018
View 14 Comments

14 Comments

  1. Raplus on August 11, 2013 6:24 am

    Hi Oscar,
    This is a great tutorial. We can use a WordPress plugin also like Wp-Insert to insert any Ad network within your WordPress post content.

    Reply
    • Oscar Frank on August 11, 2013 2:47 pm

      Thanks for the contribution Raplus, never knew of the plugin. Though I love doing lots of stuff without plugin in order to improve my blog’s load time. All the same, thanks for your valuable contribution.

      Reply
  2. Cassie on August 11, 2013 10:16 am

    It’s interesting. This is such a nice tutorial. Thank you for sharing this awesome post.

    Reply
    • Oscar Frank on August 11, 2013 2:48 pm

      I’m glad you love it and Thanks for dropping by.

      Reply
  3. doncyber on August 13, 2013 6:28 pm

    nice post dude… i am now making use of this on my weblog … its kinda amazing ……. the problem am having now is how can i insert another one in the 3rd paragraph???

    Reply
  4. Lawrence on October 15, 2013 12:42 am

    Nice one Oscar!
    I really appreciated this wonderful tip and this has stopped the nightmare of thinking about how to reduce the number of Plugins on my site
    Thanks bro!

    Reply
    • Oscar Frank on October 15, 2013 2:07 pm

      I’m glad I could help. Thanks for letting us know it did work for you

      Reply
  5. Kimsea @ Basic Blog Talk on February 28, 2014 10:17 am

    Thanks for sharing..! that is a useful to do that but I have less knowledge about coding, so this is a bit difficult for me. Anyway, thank again

    Reply
    • Oscar Frank on March 1, 2014 2:08 pm

      You are welcome pal and thanks for leaving your valuable comment. It’s been quite a while I saw you down here.

      Reply
  6. dopeboizmuzik on August 21, 2014 8:13 am

    Bro I’m using carrignton .mobile theme
    But I can’t locate the functions.php on my editor side
    So where do I locate it?
    Tnx a lot for ur interesting posts

    Reply
    • Oscar Frank on April 20, 2015 3:14 am

      It should be there. Otherwise try using file Manager via cPanel.

      Reply
  7. deejay blaze on November 28, 2014 10:15 pm

    How to display number of page views on a post?
    – WordPress …

    Reply
  8. deejay blaze on November 28, 2014 10:16 pm

    Can you tell me pls ?????

    Reply
  9. Doronize on April 12, 2017 11:10 pm

    Wow!!! It really worked for my website doronize.com
    Thanks so much bruh

    Reply
Leave A Reply Cancel Reply

Recent Posts
  • 6 Sports Apps You Must Have On Your Phone
  • Valencia Travel Guide: All You Need to Know About This Spanish Gem
  • TikTok Faces Unexpected Ban in Senegal, Sparks Global Curiosity
  • The Apple GPT & Apple’s Chatbot Mysterious Debut
  • Triller Takes on TikTok: Filing for Public Listing
Get Exclusive Tech Insights!
My Site
Facebook X (Twitter) Instagram YouTube
© 2025 Oscarmini Co. Designed by illBytes.

Type above and press Enter to search. Press Esc to cancel.