How To Insert Your Ads Inside Your Post Content either after the first paragraph or the second paragraph

1
149

Dear Beginners, At first take my cordial thanks for Visit DuniarTips.Com
Today I’m going to share how to insert your ads inside your post content either after the first paragraph or the second paragraph.
First you have to know the

benefits of Ads Placement
    A placement is an optional tool for grouping ad units. It’s a collection of one or more ad units where an advertiser’s ad can be displayed. You can create placements to identify ad units that an advertiser might want to target. Common examples include a placement for all of the leaderboards on your site, a placement for all of the seasonal ad spaces on your site, or a placement for all of the homepages in your network if you own multiple websites.
    For example, you operate a news site. You might create one placement that includes ad units for all section homepages on your site. You might create another placement that includes all ad units on pages containing content about sports. Both of these placements could include the ad unit for the front page of the sports section. Other placements might include combinations of ad units appearing in the world news, travel, and weather sections of your site. (Keep in mind that putting the same ad unit in multiple placements can lead to some reporting complexities, discussed below.)

You may also read How to Add Google AdSense to Your own WordPress blog
Most beginners wonder whether these sites insert ads manually when they write the content, or if there is a special code for this. In this article, we will show you how to insert ads within your post content after specific paragraphs.
Often when beginners want to include ads in their post, they either add the code manually which is extremely inefficient specially if you have to change advertisers, or they insert ads above or below their post using one of the ad management plugins.

Function Method

Open your theme’s functions.php or a site-specific plugin file and paste the following code:
[code]Ads code goes here

‘;

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 = ‘

‘;
$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 );
}[/code]
To add your ad code, simply edit $ad_code value where it says “Ad code goes here” . Once you do that, you are done.

Plugin Method

Simply Download and activate the plugin we given The plugin link at the footer of this post. Upon activation, the plugin will add a new menu item called Post Adverts.
Click on Post Adverts » Add New. On the next screen, simply add the name of your ad for identification purposes, enter the ad code itself, and select the paragraph you want to display the ad code after. Once done simply click publish.
[img id=2368]
Next you want to go to Post Adverts » Settings to select which post types you want to show your ads on such as posts, pages, and custom post types.
We hope that this article helped you insert ads within your post content in WordPress.

Attachments File

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

98 − 93 =