Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
25 Million+
Websites using our plugins
Years of WordPress experience
WordPress tutorials
by experts

How to Display Ad Blocks in Specific Posts in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to display ad blocks in specific posts on your WordPress website?

Inserting ad blocks into a specific post allows you to showcase ads where your users will be highly engaged with the content. This increases ad visibility and helps you get more clicks.

In this article, we will show you how to easily display ad blocks in specific WordPress posts.

Displaying Ad blocks in specific posts in WordPress

Why Display Ads in Specific WordPress Posts?

When visiting a WordPress website, you will often see banner ads in the sidebar or beneath the header. Since those are very common ad spots, they can lead to banner blindness, where users won’t notice the ads. In turn, this can affect the click rate.

By displaying ad blocks in specific WordPress posts, you can increase the visibility of your ads and target users who are most engaged with your content.

Not only does this help prevent ad fatigue by spreading out ads across multiple pages on your WordPress blog, but it also allows you to segment your audience. By showing targeted ads to users who are more likely to be interested in them, you improve your chances of engagement and clicks.

For example, a user who is reading one of your travel blog posts is more likely to be interested in an ad for travel gear or flights and may click on it to check out the prices.

Having said that, let’s see how to easily display ads in specific WordPress posts. You can use the quick links below to jump to the method you wish to use:

Method 1: Display Ad Blocks in Specific WordPress Posts Using WPCode (Recommended)

The easiest way to display ad blocks in specific WordPress posts is by using the WPCode plugin.

It is the best WordPress code snippets plugin on the market that makes it super easy to place ads within any page, post, or widget area on your WordPress website.

With WPCode, you can show advertisements from third-party platforms like Google AdSense or your own hosted ads.

First, you need to install and activate the WPCode plugin. For more detailed instructions, please see our beginners’ guide on how to install a WordPress plugin.

Note: You can also use the free WPCode plugin for this tutorial. However, upgrading to the Pro version will give you access to a cloud library of code snippets, smart conditional logic, and more.

Upon activation, head over to the Code Snippets » + Add Snippet page in the WordPress admin sidebar.

From here, click on the ‘Use Snippet’ button under the ‘Add Your Custom Code (New Snippet)’ option.

Add new snippet

This will take you to the ‘Create Custom Snippet’ page, where you can start by typing a name for your code snippet. The code snippet title is only for your reference and won’t be shown to users on the website’s front end.

After that, select ‘HTML Snippet’ as the Code Type from the dropdown menu on the right.

Choose HTML Snippet as code type for displaying ad blocks

Next, you need to choose the type of ad you want to place on your site.

If you are using the ad code provided by Google AdSense, then you may want to see our guide on how to optimize your AdSense revenue in WordPress.

However, if you are creating your own ad, then you must get the code from the person who is paying you to show the ad on your site or write your own code.

Upon getting your ad code, simply copy and paste it into the ‘Code Preview’ box.

Copy and paste ad code into Code Preview box

Once you have done that, scroll down to the ‘Insertion’ section and choose the ‘Auto Insert’ mode.

The ad will automatically be displayed in the specific post you pick.

Choose an insertion method

Next, click on the ‘Location’ dropdown menu to expand it, and then select the ‘Page-Specific’ tab from the left sidebar.

From here, choose the ‘Insert After Paragraph’ option.

You can also modify the number of paragraphs after which you want to insert the snippet.

For example, if you want to display the ad block after the 3rd paragraph, then you can type this value into the ‘after paragraph number’ box.

Choose Insert After Paragraph as the snippet location

Next, scroll down to the ‘Smart Conditional Logic’ section and toggle the ‘Enable Logic’ switch to Active.

After that, make sure that the ‘Show’ option is selected for the code snippet condition. Once you have done that, just click the ‘+ Add new group’ button.

Toggle the Conditional Logic switch to active

This will open up some new settings in the ‘Smart Conditional Logic’ section.

From here, you need to select the ‘Page URL’ option from the dropdown menu on the left.

Choose the Page URL option from the dropdown menu on the left

After that, you must select the ‘Is’ option from the dropdown menu in the middle.

Next, add the URL of the specific post where you want to display the ad block into the empty field in the right corner of the screen.

If you want to display this ad on more than one page or post, just click ‘AND’ and then follow the same process to insert the other post URL.

Once you have created this conditional logic, your ad block will only be displayed in that specific WordPress post.

Add the specific post URL

Now, scroll back to the top and toggle the ‘Inactive’ switch to ‘Active’.

Finally, click the ‘Save Snippet’ button to execute the ad code on your website automatically.

Save the snippet for ad blocks

Now, you can visit the specific post you chose to see the ad block in action.

This is what it looked like on our demo website.

WPCode Ad Preview

Method 2: Display Ad Blocks in WordPress Posts Using AdSanity

If you don’t want to use code on your website, then this method is for you.

AdSanity is a premium WordPress ad management plugin that allows you to easily create ad blocks and display them anywhere on your WordPress site. It works with any third-party ad network, including Google AdSense.

First, you need to install and activate the AdSanity plugin. For more details, please see our step-by-step guide on how to install a WordPress plugin.

Upon activation, head to the Adsanity » Create Ad page from the WordPress admin sidebar.

From here, you can start by typing a name for the ad that you are creating.

Next, you must switch to the ‘Ad Hosted On-Site’ tab at the top if you are creating your own hosted ad.

Type Ad name

However, if you are displaying an ad from a third-party platform, then go to the ‘External Ad Network’ tab. Similarly, if you want to upload an HTML file for your ad, then you must switch to the ‘HTML5’ tab.

For this tutorial, we will be displaying a self-hosted ad in a specific WordPress post, but the steps will be the same for other types of ads.

Once you have entered a name for your ad, select its size from the dropdown menu. This will be the banner size of the ad in your post.

Choose an Ad size

After that, scroll down to the ‘Ad Details’ section and copy and paste the tracking URL of the ad you want to display.

Once you have done that, check the ‘Open in a new window?’ option if you want the ad to open up in a different window when a user clicks on it.

You can also set an image for your ad by clicking on the ‘Set ad image’ link. This will open up the WordPress media library, where you can upload an image.

Paste the tracking URL for the Ad and set an image

Finally, click the ‘Publish’ button at the top to save your changes.

You can also click on the ‘Edit’ link in the ‘Publish’ section to set a start date and an expiration date for the ad.

Once you have clicked on the ‘Publish’ button, you can display the ad block on any page or post on your WordPress website.

Set an Ad schedule

Display the Ad in a Specific WordPress Post

First, you will need to open an existing or new WordPress post where you want to display the ad you created.

Once you are there, click the add block ‘+’ button in the top left corner of the screen to open up the block menu. Next, look for and add the AdSanity Single Ad block to the WordPress post.

Add the AdSanity Single Ad block

After that, select the ad that you want to display from the dropdown menu in the block.

You can also choose an alignment option for the ad block.

Choose Ad from dropdown menu

Finally, click the ‘Update’ or ‘Publish’ button at the top to save your changes.

Now, you can visit your website to check out the ad block in action.

Ad Preview

Bonus: Add Amazon Ads to Your WordPress Site

Other than promoting ads from other small businesses, you can also display Amazon ads on your WordPress site.

These ads have a super fast approval rate, helping you easily earn money online. Plus, with Amazon, you can choose from a wide variety of products that are relevant to your niche, encouraging more users to click on them.

You can easily showcase Amazon ads on your own by creating an account on the Amazon Associates Program website.

Amazon Associates Program

Once you do that, simply generate your Amazon ads code and then display ads on your website using plugins like Pretty Links.

You can also create popups for your Amazon ads with OptinMonster, which is the best conversion optimization tool on the market.

For detailed instructions, see our tutorial on how to add Amazon ads to your WordPress site.

We hope this article helped you learn how to display ad blocks in specific WordPress posts. You may also want to see our tutorial on how to sell ads on your WordPress blog and our expert picks for the best affiliate marketing tool and plugins for WordPress to make money online.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

18 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Jiří Vaněk says

    Thanks for the great tutorial. I currently have Adsense with Google, but I don’t use it on the site. I was waiting for my traffic to grow a bit more. For the year 2024, I would like to monetize the website in the form of Adsense and I was thinking about how to do it. This article showed me a lot. Thank you very much for the explanation and practical examples.


    Thank you for this tutorial. However, please between WPCode and Adsanity which one has a better free version?
    I want to use the free version can you recommend any one for me?

  4. Ahmed Omar says

    A game-changing tutorial on displaying ad blocks in specific posts in WordPress!
    Your step-by-step guide, especially the use of conditional tags, is a smart way to monetize specific content.
    A technical tip: consider experimenting with Ad Plugin for advanced ad management and tracking. Thanks

  5. Ram E. says

    Thanks for this another helpful post.

    I’m exploring options as I’m planning to directly sell ad space on my blog in the near future. I also already read your guide on the best ad management plugins.

  6. Ralph says

    I was using Google Adsense auto placement and it is not optimal. In short content it looks like spam, and in long content there are even 2 or 3 full screen between ads. I want to change it and use some plugin. I was using “adinserter” to put shortcode in posts and change everything at once but it was for my products or affiliate banners. I’m wondering if the plugin is even neccessary. We have built in WordPress blocks that can do the same. Isn’t it better for optimization to use that blocks rather than additional plugins?

    • WPBeginner Support says

      You can use the built-in blocks to include ads, the main thing that plugins allow is more options instead of only manual placements. There shouldn’t be a major optimization difference between using a default block and a plugin.


  7. Kawsar Ahmed says

    Awesome article. Thank you so much for sharing tips.

    I have a question, I have inserted multiple Google ads code inside an article with the wordpress default html block.

    While doing this I have removed the bellow line only except the first one. It’s because the code is similar.


    I thought if the resource was included once then it would work for all the available ads.

    Please reply to me, is my thinking correct? Or if I am doing this, is there any possibility of mistracking to get the ads clicks revenue.

    Thanks again!

    • WPBeginner Support says

      Unless we hear otherwise that should be doable with how Google’s ads work at the moment.


  8. Bella says

    Hi there, I tried to install AdSanity but it does not come up in WP searches in the add new plugins section. Has it been discontinued and can you recommend a replacement?

  9. raman says

    Great post. Wonderful information and really very much useful. Thanks for sharing and keep updating.

  10. Narendra Singh says

    I have a website and I want to have a theme which has “Read More” or “Continue Reading” option and which is very easy to search in google search engine. Right now I have “Twenty Twelve” theme.

    Kindly suggest


Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.