1. Home
  2. WordPress Tutorials
  3. How to Add Ads to Your Post Content in WordPress

How to Add Ads to Your Post Content in WordPress

Do you want to add ads to your post content in WordPress? Ads are one of the main ways a website makes money, but with the rise of Ad Blocker, many websites are making less. To deal with this issue, you can try and force visitors to disable their Ad Blocker, but you generally just end up losing a visitor.

Another way, but even riskier, is to increase the number of ads on your website. Why is this riskier, you ask? Many people have resorted to Ad Blocker to avoid ads entirely and increasing the number will make it an easier choice for those who have not. Today, I will demonstrate how to add ads to your post content in WordPress.

Don’t Make Ads Feel Like Punishment

One of the biggest complaints by many visitors is seeing ads that have nothing to do with them or the website they are visiting. This should be easy to understand because everyone experiences ads. Placing ads on your website is important and helps you earn money, but you have to make sure they are the right kind of ads. For example, kids do not care about car insurance, so do not have car insurance ads on a children’s website.

Understanding your audience is extremely important and can help you pick out the right ads for your audience. In addition, you can also use Google Adsense which is an advertisement tool that displays ads that are relevant to visitors who see them. You do not have to pick the ads and many websites benefit tremendously from the platform.

How to Add Ads to Your Post Content in WordPress

Today, I will demonstrate how to add ads to your post content in WordPress. There are two methods to add ads to your post content. The first is to use the Insert Post Ads plugin. The second is to edit your theme’s functions.php file and add a few lines of code. Both methods are very quick, but if you do not like code editing, then I recommend the plugin method.

Method 1: Insert Post Ads Plugin

Installing Insert Post Ads Plugin

Let’s start by going to the plugins area of WordPress and click on the “Add New” button.

click on the "Add New" button.

Search for Insert Post Ads in the available search box. This will pull up additional plugins that you may find helpful.

Search for Insert Post Ads in the available search box.

Scroll down until you find the Insert Post Ads plugin and click on the “Install Now” button and activate the plugin for use.

click on the "Install Now" button

On the left-hand admin panel click on Post Adverts and select the Add New Post option. This will pull up the main settings page.

click on Post Adverts and select the Add New Post option.

Using Insert Post Ads

Adding advertisements is easy with this plugin. You should add a title to the ad first. This title is for you to recognize the various ads you set up on your website. Add the title to the appropriate text box.

Add the title to the appropriate text box.

Next, you need to add the advertisement code to the Advert Code text box.

Add the advertisement code to the Advert Code text box.

Lastly, you need to choose where the advertisement will be displayed. You have three choices which include Before the Content, After Paragraph Number, and After Content. If you choose the paragraph number option, you will be able to decide after which paragraph the ad will be displayed. Choose the best option for your website.

Choose the best option for your website.

Once you are done click on the “Publish” button to save your work. You can repeat these steps to add as many as ads necessary.

Click on the "Publish" button.

All that is left is to assign where the ads will be displayed. Click on Post Adverts. You will see a Display settings box. Here you can choose between posts, pages, and templates. You will also see an Exclude CSS option, but that should only be checked if you want to use custom CSS instead of the default code the plugin uses. Click on the “Save Settings” button when you are done.

Click on the "Save Settings" button.

Congratulations, your ads will now be displayed in your post content if you chose the posts option. You can change these settings at any time and add as many ads as necessary. Remember that most people do not like advertisements so refrain from ads that get in the way of content or make loud sounds. If you wouldn’t like seeing it, neither will your visitors.

Method 2: Code

Let’s start by logging into the cPanel and clicking on the File Manager option. The File Manager will allow you to access all of the files related to your website.

Click on the File Manager option.

You need to locate your theme’s functions.php file. Click on the public_html directory, then click on the wp-content folder. Inside of this folder, you will find all of the content related to your website. Click on the themes folder and enter the folder of the theme you are currently using. Finally, right-click on the functions.php file and select the Edit option.

Select the "Edit" option.

A pop-up window will show up. This box will warn you to create a backup of your files before editing anything. This will ensure that you can revert your website back to when it was working if something goes wrong. Click on the “Edit” button. A new tab will open containing all of the code from the file.

Click on the "Edit" button.

Copy and paste the following code segment into your functions.php file:

<?php

//Insert ads after a specific paragraph number in post content.

add_filter( ‘the_content’, ‘prefix_insert_post_ads’ );

function prefix_insert_post_ads( $content ) {

$ad_code = ‘<div>Insert Your Advertisement Code Here</div>’;

if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, Insert Paragraph Number Here, $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 );
}

There are two things you must edit in this code segment. The first is adding your advertisement code. Replace “Insert Your Advertisement Code Here” with your actual advertisement code. The second is to decide after what paragraph you would like to place the advertisement. Replace “Insert Paragraph Number Here” with the actual paragraph number. For example, if you want the ad after paragraph 4, use the number 4.

Once you have inserted the code into the functions.php file, click on the “Save Changes” button to finish.

Click on the "Save Changes" button.

Congratulations, you have successfully added advertisements to your post content without a plugin. You can edit this code at any time and to remove it, simply delete the code segment.

Find the Perfect Balance of Ads on Your Website

Nobody likes to see ads on websites, but they serve an important purpose as they fund your website. Many people will go out of their way to avoid ads or simply go to another website. Adblocker is also something you need to decide on. Some websites will block visitors who use it, warn visitors that it hurts the website, or simply ignore it. There is no right way to handle the issue.

If you choose to block people completely, remember that you are turning away a visitor that could potentially tell all of their friends to visit as well. On the flip side, that person is viewing all of your content without seeing ads, which is the same as not paying you for your work. It is hard to say which is the right approach, but in either case, someone is losing something.

Which method have you chosen to use? Where have you placed your ads in your post content?

Author: Chris Racicot

Chris is the Support Manager at GreenGeeks and has been with the company since 2010. He has a passion for gaming, scripting and WordPress. When he’s not enjoying his sleep, he’s working on his guitar skills and fiddling with 3d printing.

Updated on May 1, 2018

Was this article helpful?

Related Articles

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.