Do you want to insert ads within your post content in WordPress?
Your post content is the place where visitors are most engaged with your website, which makes it the perfect place to show an ad.
In this article, we will show three ways to insert ads within your post content in WordPress.

Why Insert Ads Within Your Post Content in WordPress?
Banner and sidebar ads are a great way to make money online blogging with WordPress. However, they’re also easy for visitors to ignore.
People visit your site to read your content, and may not pay as much attention to your sidebar or other areas of the page. Since your post content gets the most attention from visitors, it’s the perfect place to show ads.
With that being said, let’s look at three different ways to insert ads within your post content in WordPress.
If you prefer to jump straight to a particular method then you can use the links below.
1. AdSanity
One way to insert ads within your post content is by using the AdSanity plugin.
AdSanity is a premium WordPress ad management plugin. It allows you to place ads on any page, post, or widget-ready area using shortcode.
You can then either upload your own ads or show advertisements from third-party networks such as Google AdSense. For more information, see our guide on how to manage ads in WordPress with AdSanity plugin.
First, you’ll need to install and activate the plugin. If you need help, then please see our guide on how to install a WordPress plugin.
Upon activation, go to AdSanity » Create Ad.

To get started start, you’ll need to give your ad a title by typing into the field that shows ‘Give this ad a title.’
Your site visitors won’t see the title since it’s for your own reference only.

Next, you need to choose the kind of ad that you want to create. One option is to build your own ad and host it on your website, which is perfect for selling ads on your WordPress blog.
Another option is to use the ad code provided by a program like Google AdSense.
To start, let’s see how you can create a hosted ad using AdSanity’s built-in tools. First, click on the ‘Ad Hosted On Site’ tab.
Next, you can choose how big your advertisement will be on your website by opening the ‘Ad Size’ dropdown and choosing a size from the list.

Once you’ve done that, you’ll need to type a tracking URL into the ‘Tracking URL’ field. This is the URL that the ad will link to.
By default, this URL will open in the same browser tab. However, you may want it to open in a new tab, particularly if the advertisement is linking to someone else’s website.
To make this change, simply check the ‘Open in a new window’ box.

Once you’ve done that, scroll to the Ad Image section. Here, you can upload the image that WordPress will use as your ad.
To upload a banner or other ad graphic, simply click on ‘Set ad image.’ You can then upload or choose an existing image from your WordPress media library.

To help organize your ads, you may want to create some advertisement groups. For example, you might create a ‘holiday advertisements’ group for all the ads you plan to use around the holiday season.
To create an advertisement group, click on the Add New Group link. This adds a new section where you can type in the title for the group.

Just like WordPress categories and subcategories, you can arrange your advertisement groups into parent-child relationships.
If you have lots of different ads, then organizing them into parent and child groups can make it easier to find exactly the ad you’re looking for.
When you’re happy with how your advertisement group is set up, click on the ‘Add new Group’ button to save your changes.
To add your advertisement to a group, simply check the group’s box.

Once you’ve finished working on your ad, it’s time to publish it. If you want to show the ad right away, then go ahead and click on Publish.
Another option is to schedule the ad so it will show up on your WordPress website at some point in the future. To schedule your ad, click on the ‘Edit’ link next to ‘Publish forever.’

WordPress will now show some settings that you can use to set the date and time when this ad will be published.
You can also use these settings to choose when the ad will be put back into a draft state. When this happens, the ad will disappear from your WordPress blog or website.
If you don’t want the ad to expire, then just click on the ‘Publish Forever’ button.

You’ve now successfully created a hosted ad.
While you can sell advertising space directly to other businesses, many website owners use an advertising network instead. These networks are often hassle-free because you don’t have to deal with advertisers or worry about collecting money.
Instead, the network decides which ads to place on your site, collects the payment, takes their management fee, and then sends the rest of the money to you.
If you’re using an advertising network, then click on the External Ad Network tab.

Next, type in a title and add your advertisement to any groups following the same process described above.
You can also choose a size for your ads. If you’re using Google AdSense, then you may want to see our guide on the highest performing Google AdSense banner sizes and formats. We also have a complete guide on how to optimize your AdSense revenue in WordPress.
Once you’ve done that, you’re ready to copy the advertisement code provided by your network. Then, simply paste this code into the ‘Ad Code’ section.

When you’re happy with how your ad is set up, you can either publish it or schedule it following the same process described above.
No matter what kind of ad you create, the next step is placing the ad on your website. The steps are exactly the same for hosted ads and ads provided by a network.
To position your ad on any page, post, or widget-ready area go to AdSanity » Manage Ads.
On this screen, find the ad that you just created and click on its shortcode link. This will copy the shortcode for this advertisement.

You can now either create a new page or post, or open one for editing. Then, simply find the exact place where you want to show this ad within your post content, and create a new shortcode block.
You can then go ahead and paste the code into this block. For step by step instructions, see our beginner’s guide on how to add a shortcode in WordPress.
If you’ve already published the ad, then you can visit the page or post to see the ad within your post content. If you scheduled the advertisement instead, then the ad will appear on your site at the date and time chosen by you.
2. Ad Inserter
Another option is to use Ad Inserter. This is a WordPress ad management plugin that can show both hosted ads and advertisements provided by a network.
If you’re using a network then you can simply paste your ad code into the Ad Inserter plugin. However, if you’re creating a hosted ad, then you’ll either have to write the code yourself, or get it from the person who is paying to show their ad on your website.
First thing you need to do is install and activate the free Ad Inserter plugin. If you need help, then please see our guide on how to install a WordPress plugin.
Upon activation, go to Settings » Ad Inserter.

On this screen, each tab is a different advertisement. This allows you to create multiple different ads, and place them on your website.
You can now either type in or copy/paste the code for the advertisement that you want to show within your post content.

The next step is placing this ad on your website. One option is to add the advertisement to any page, post, or widget-ready area using a shortcode.
Another option is to tell Ad Inserter to automatically add this advertisement to every post, at a certain location such as after every third paragraph.
If you want to add this advertisement to your posts automatically, then start by checking the ‘Post’ box.

Next, you’ll need to open the ‘Insertion’ dropdown and choose where Ad Inserter should show this ad.
Since we want to insert ads within the post content, you’ll typically want to choose either Before Paragraph, After Paragraph, Before Image, or After Image.

After choosing an option from the list, type in exactly where this ad should appear.
For example if you wanted to show the ad after the second paragraph, then you would type in ‘2’ as you can see in the following image.

When you’re happy with your settings, click on the ‘Save Settings’ button.
Ad Inserter will now insert this ad within your post content, in your chosen location.

Just like we mentioned earlier, you can also place this ad on your site using a shortcode.
To do this, click on the ‘Manual’ button and then check the ‘Shortcode’ box.

Once you’ve done that, just copy the Ad Inserter shortcode. You can then click on the ‘Save Settings’ button to save your ad.
With that done, you’re ready to place this shortcode on any page, post, or widget-ready area. For step by step instructions, you can see our guide on how to add a shortcode in WordPress.
3. Code Method
You can also add an advertisement to your post content in WordPress using code.
Since you’re editing your site’s code, this isn’t the most beginner friendly method. However, it does allow you to create ads without having to install a special ad management plugin.
To insert an ad using code, either open your theme’s functions.php file, create a site-specific plugin, or use a code snippets plugin.
You can then add the following code:
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Ads code goes 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 );
}
This code will show an advertisement after the second paragraph of a post’s content.
If you want to show your ad in some other location, then you simply need to change the following section:
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 3, $content );
}
In the sample code above, you can see that we’re inserting the ad after the third paragraph.
Once you’ve done that, you can go ahead and either type in or paste your ad code. This is the code that controls how your ad looks and acts.
You’ll add this code as the $ad_code value, which is where it says ‘Add code goes here.’
$ad_code = '<div>Ads code goes here</div>';
After you’ve done that, you’re ready to publish your ad. To do this, either activate your site-specific plugin, save your code snippet, or save the changes you’ve made to your site’s functions.php file.
Now if you visit your website, you should see your ad live.
We hope this article helped you learn how to insert ads within your post content in WordPress. You may also want to learn how to increase your blog traffic, or check out our list of the best WordPress tools and SEO plugins that you should use.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Erika says
Will the Ad Sanity allow to place external ads on an individual post only not on the entire site?
WPBeginner Support says
If you wanted to you can only display ads on one post!
Admin
George says
Is there any way how to insert different ads after multiple paragraphs? For example AdSense ad no 1 after 2nd paragraph, AdSense no 2 ad after 6th paragraph?
WPBeginner Support says
If your ad network has different ads to display then method 2 should allow for what you are wanting currently
Admin
Gideon says
will this code replace the entire existing code of the theme child theme?
The <?php start is returning error
WPBeginner Support says
It will not replace your entire theme’s design. For pasting the code in your functions.php you could try removing that opening PHP tag to see if that helps solve the issue.
Admin
Marvin says
How can i make it to repeat (For Example. to repeat after paragraph 2.)?
WPBeginner Support says
We do not have a recommended method for having the code repeat at the moment.
Admin
Deepak says
Fascinating. It is so easy. Thank you guys.
WPBeginner Support says
You’re welcome
Admin
Mi Monir says
This is working. Thanks a lot.
WPBeginner Support says
You’re welcome
Admin
Oniel says
Can you please update the plugin to be able to add the code “before” the first paragraph instead of “after” the first paragraph?
WPBeginner Support says
The plugin does have the option to insert before your post content instead of after a paragraph number
Admin
Shannon says
This is amazing, thank you so much for this. Do you know why my ad goes to the left of the post and not in the middle?
WPBeginner Support says
The most common reason would be if your theme has styling that is forcing that alignment.
Admin
Karthik says
how much time take for adsense ad display on our site once we get approved after the code placed.
WPBeginner Support says
That would be a question for Adsense as they may not have ads they would currently offer for your site.
Admin
Sangam says
Thank you, with the help of this snippet I managed to show ad after each 300 words. I just added word count instead of paragraph.
WPBeginner Support says
Glad we could give you a starting point
Admin
Chango says
Hello is that Insert posts ads plug in good? or does it crash the site or slow it down? I am nervous because 7 years ago I used a adsense plug in and the maker of the plug in was adding their ads on my website.
Is this insert ads plug in good that you recommend. Does it mess with coding or slow down the site?
thanks.
WPBeginner Support says
Unless you manually add problematic code, the insert post ads plugin shouldn’t harm your site’s speed.
Admin
Arkantos says
Works great! But I noticed it also counts the paragraphs from an embedded tweet. Is it a way to avoid that and count only text paragraphs from the content/article?
WPBeginner Support says
Sadly, not at the moment.
Admin
Von says
Is there a wordpress tag to have a ‘content/block’ automatically injected into the middle of my blogs.
I’m looking for documentation (I’d seen it before). I would appreciate any help here.
Thank you.
WPBeginner Support says
For what it sounds like you’re wanting, you would want to use the recommendation from the article
Admin
Willys says
Hi, I have just Signed up to Google adsense but I am having a problem of how to copy my Google adsense code to my website (WordPress). How can i do it?
WPBeginner Support says
For adding Adsense you would want to take a look at our article here: https://www.wpbeginner.com/beginners-guide/how-to-add-google-adsense-to-your-wordpress-site/
Admin
Sangam says
I am using this code snippet in my child theme function.php to make ads appear in 3rd paragraph. But I want it to repeat after each 3 or 4 paragraph. How it can be done?
WPBeginner Support says
As we state in the article, you would change the number in the code snippet to change where the ad appears.
Admin
Sangam says
How to repeat? After 3rd/6th/9th/12nd etc?
WPBeginner Support says
If you wanted the ad to display multiple times then inside the if statement where it has: return prefix_insert_after_paragraph
You would want a new line where you add a copy of the prefix_insert_after_paragraph with a different paragraph number
Ahsan Ali says
How to insert ad after each & every 3rd paragraph in a single post?
Kindly guide!
WPBeginner Support says
You would need to use the site-specific plugin method and change the 2 to a 3 on line 12
Admin
Peter says
Hi
Only the code is showing on my post no images. The code is just lying there in the post, you won’t even notice it’s there
What can I do to change this
I need the banners showing in the post
WPBeginner Support says
You may want to ensure you added the code with all of it’s tags correctly for your ads and didn’t skip any tags.
Admin
Ngo says
Hello,
Thank you for the manual code. It seems to be working for everyone but I just can’t get it to work on my site. My site is made up of only Custom Post Types. Is this why it is not working? Please what do I need to change in the code to make them display on my custom post types?
Even ordinary widgets do not display on my site. Is there anything I can include in my functions.php to make changes display on my custom pages?
Please help, I have tried every code on the internet and none of them works.
WPBeginner Support says
If you want to use the custom code on a custom post type and the method we have is not working, you could try changing is_single() to: is_singular( $post_types = ” )
and place the name of your custom post type in the single quotes
Admin
Swagatam Innovations says
It worked like charm, thanks very much for this code!
WPBeginner Support says
Glad our article could help
Admin
Minh Hieu says
Can you help me?
How to insert ads before an ID element?
Ex: i want to insert ads before
Thanks you very much!
JOHN HOBBS says
Thanks for everything you provide. It’s truly appreciated. But question. This article reads
Last updated on May 2nd, 2014
at the top. Is the information presented still valid and up-to-date?
You guys have been a tremendous help to me so I feel bad asking but I need to know.
Again, thanks for the great resources you provide!
John
WPBeginner Support says
Hi John,
The plugin mentioned in the article is still available and works great.
Admin
Tell.com.ng says
Please I need a clearly defined way to add more than one ad after different paragraphs.
Reply needed urgently please.
Thanks!
Atul says
i am using infinite scroll featured theme and post advert plugin for ads but ads show only on first post, not next post. how can i solve it. this plugin does not repeat ads between post.
Melissa says
This is by far the easiest plugin I’ve ever used! It works perfectly and looks great. Thank you so much! WPBeginner has been a huge help to me in starting my new blog!
rishabh shrivastava says
It was helpful! Thanks
sandeep says
thank you so much its working dude
Hoàng Trí says
So I Want to insert ads by tag (Like Gym, Fitness) only two tag will show ads, and other will not. How i can do it ?
Bob says
How can I place an ad before the first paragraph..underneath the single post image? When i set the number to”0″…nothing happens?
Qasim Iqbal says
Hey, If I added the code using Post advert, would it be on every post? right?
If not then tell me, I want that
Bright Joe says
Thank you so much for the code for the functions.php. This just lets me avoid so many unnecessary plugins.
Thanks again!
Martijn says
Hi,
Thanks for the code!
How can I exclude certain posts?
Greetings,
Martijn
David says
Was sincerely helpful to start off for my presentation at Kampala WordCamp 2017.
Really incredible help from you.
Segun says
how can i insert HTML code in my ad space?
Adem says
for more as one ad, change to this:
$ad_code = ‘Ads code goes here’;
$ad_code2 = $ad_code;
if ( is_single() && ! is_admin() ) {
$content = prefix_insert_after_paragraph( $ad_code, 2, $content );
$content = prefix_insert_after_paragraph( $ad_code2, 8, $content );
return $content;
}
return $content;
}
Thanks!
Bright Joe says
Thank you so much!
Akios says
Don’t know how to insert it
Sunil Kumar says
Thanks! It worked.
Shehab says
I want to show two ads on my post. How can I do it?
That process you showed, here I can see only one ad on every post. but I want to show two ads in every post
shuseel says
I want to implement ads code other than Adsence code using JavaScript code.
The above code does not work when I have replaced JavaScript code on Ads code goes here.
Please suggest me how to implement
on the place of text.
phil says
Hi,
Congratulation for this function.php code ! Works well
I ve a question :
How can i do for do not display adds on specific posts or pages ?
Many thx
Regards
Phil
Andrea says
Nice code! How insert only for a certain author post?
Aditya says
I am using Admiral theme and I want to display ads above the thumbnail of every post. What can I do ?
Shubhamk says
I installed the plugin, I created my ads in the post but it appears at the bottom, not at the start.
Sally says
Hi, I installed the plugin on my wp site and followed the instructions – post ad and edit settings to show ads on posts. But the ads don’t show on my posts. Do you know why? thanks in advance!
Gail says
Have just started using the plug-in and it works great!! A question: I now want to insert a new ad. Do I have to trash the old one and then create a new one? Or can I reserve the old one for a future use? Seems like I do have to trash it to make room for the new one. Thanks.
Percival says
I am wondering if it’s possible to insert a widget, rather than $ad_code = ‘Ads code goes here’;
Is this possible? I can’t seem to implement the syntax correctly, as inserting a widget seems not to respect the paragraph numbering, and randomly inserts a “1” into the text:
$ad_code .= dynamic_sidebar(‘test’);
John says
Percival, did you figure out a solution? Trying to do something similar.
Morgan says
Where do I get a code for an ad .?
hassan says
did you mean code for ads?………
you have to visit your ads network be it google adsense or for your ads code then insert it between insert here……….
Stephen says
You have to make a Google Adsense account and make an ad within that. Then, you take the code they give you for the newly created ad and insert it there.
Jagadish Prasad B says
I want to put my ads in the middle of the content by using an editor. Pleas e suggest me how to add the code in the editor. Thanks for the support.
Ryan S says
Creating shortcode is the best fit on your end, so first, you need to create Shortcode ads and then use that shortcode in your article/post.
Ryan S
hsabarp says
thanks
this is the what i was searching for…….
Vỹ Spirit says
Hello, After I add the above code to the function.php file, my article does not display ads, instead, and it’s adsbygoogle text …. How do I fix it?
hassan says
i did mine some minutes ago and it work well try to remove the <?php if your functon.php already have it…….
Enrique Grobbelaar says
This app seems to work for everyone, except me.
I have followed all the steps, said it should display after paragraph 3. Now there is a large white block on all posts below paragraph 3, but no ad.
Does somebody perhaps know what I am doing wrong?
(Using Google Adsense)
Enrique Grobbelaar says
Never mind. It is working now.
Great says
Thanks you for the tutorials, I used the post ad on my site is working perfectly well but can not open in a new window. Pls how do I set the post ad banners to open in a new window?