How to Insert AdSense Ads within Post Content in WordPress

google-adsense-money

For many bloggers, Google AdSense is one of the popular ways to earn money. More often than not, this AdSense money is used to maintain the blog or website and even motivates to write and do more. Generally, you can show AdSense ads anywhere you want, including within posts in WordPress. In fact, you might have seen many websites inserting ads within post content in WordPress.

The ads within post content in WordPress will have high CTR (Click Through Rate). When you have high CTR, you earn more. So, if you ever wonder how to insert AdSense ads within post content in WordPress then here is how to do it in a simple way.

Insert AdSense Ads within Post Content

I’m going to show you two methods to insert AdSense ads within post content in WordPress.

  • The first method is to use a free plugin. Best method if you want ease of use and flexibility.
  • The second method is to use a simple code snippet. Best method if you don’t want to use yet another plugin for a simple task.

Follow the method you are comfortable with to show ads within post content in WordPress.

1. Insert AdSense Ads within Post Content – With Plugin

To show ads within post content, you can use a free plugin called Ad Inserter. This plugin is pretty simple to use and has all the features you’ll even need.

Features of Ad Inserter Plugin

Below are some of the notable features you get with the free plugin.

  • Supports 16 ad blocks
  • Automatic ad insertion is several different places including but not limited to within posts, after and before posts, etc.
  • Support for widgets and shortcodes
  • Ad rotation
  • Device detection
  • Ability to add custom CSS classes
  • Custom alignment options
  • Ability to blacklist and whitelist categories, tags, posts, pages, referrers, etc.
  • Ad preview with visual CSS editor

and much more.

Configure Ad Inserter Plugin to Show Ads

1. To start off, download and install Ad Inserter like any other WordPress plugin.

2. Once installed, navigate to “Settings > Ad Inserter” to open the plugin settings page.

add google adsense ads within post content open ad inserter settings page

3. The above action will take you to the plugin settings page. Here, select the code block tab “1” and enter your AdSense code. The good thing is, you can enter any ad code you want. In fact, you can even add your own affiliate links with banners.

add google adsense ads within post content add ad code

4. Below the code block, you will see a few options. These options enable you to set the ad placement and alignment. Follow the below steps to configure them.

  1. Select the option “After Paragraph” from the drop-down menu next to Automatic Insertion.
  2. Choose the alignment style from the drop-down menu next to Alignment and Style. In my case, I chose my alignment style as “Center.”
  3. Now, in the field next to “Paragraph Number,” enter the paragraph number after which the ad should appear. In my case, I want to show the ad after the first paragraph. So, I’ve entered, “1” in the field.
  4. Click on the button “Save All Settings” and you are good to go.

add google adsense ads within post content ad placement settings

That’s all there is to do. From this point forward, ads will appear within post content as configured. While you are at it, make use of the additional ad blocks and display ads on other places as required.

While you are at it, make use of the additional ad blocks and display ads on other places as required. Since the plugin gives you a lot of control, play with different settings to make most out of the plugin.

2. Show AdSense Ads within Post Content – Code Snippet

If you don’t want to use a plugin to insert ads within post content then you can use a simple code snippet to get the work done.

1. To start off, open your favorite FTP client, navigate to your active theme folder and then open the file functions.php. Alternatively, you can also edit functions file by navigating to “Appearance > Editor” and then selecting the option “Theme Functions” appearing on the right sidebar.

add google adsense ads within post content open functions file

2. Once the functions file has been opened, copy the below code and add it to the file. After adding, don’t forget to make the below changes to the added code.

  1. In line 7 of the code, enter the paragraph number after which the ad should appear. By default, the ad will appear after the first paragraph.
  2. Replace the text “insert adsense code here” with the actual Adsense code.
Note: you can also the below code in your site-specific plugin.
//Display ads within post content
add_filter( 'the_content', 'bs_inpost_ads' );
function bs_inpost_ads( $content ) {
        if( !is_single() )
            return $content;

        $afterParagraph = 1; //Enter Paragraph Number
        $content = explode ( "</p>", $content );
        $new_content = '';
            for ( $i = 0; $i < count ( $content ); $i ++ ) {
                if ( $i == $afterParagraph ) {
	                    $new_content .= '<div style="min-height: 5px; width:auto; text-align:center;">';
	                    $new_content .= 'insert adsense code here';
	                    $new_content .= '</div>';
                }
                $new_content .= $content[$i] . "</p>";
            }
        return $new_content;
}

With the above code, you are done inserting AdSense ads within the post content. By changing the paragraph number, you can display ads after any number of paragraphs.

That’s all there is to do and it is that simple to insert AdSense ads within post content in WordPress.

Do comment below sharing your thoughts and experiences about using the above methods to show or insert AdSense ads within post content in WordPress.

2 Comments

  1. Hello, Vamsi! I noticed this new function of your site, related articles in the body of the post, found it very interesting and is something I have been looking for some time. Could you tell me how you installed it? I have used a plugin, but it is very heavy which leads me to want to put it without using the plugin. Could you show me how to do this?

Leave a Reply

Your email address will not be published. Required fields are marked *

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