Have you seen blogs that have ads within their post content? These ads are found after the first paragraph or the second paragraph in most cases. Most beginners wonder if these sites insert ads manually when they write the content, or if there is a special code for this. In this article, we'll show you how to insert ads within your post content after specific paragraphs.
Often when beginners want to include ads in their post, they add the code manually, which is extremely inefficient, especially if you have to switch advertisers, or insert ads above or below your post using one of the ad management plugins ..
Well, we have been adding ads in List25 after the first few paragraphs, and many users asked about it, so this is the easiest way to do it.
Simply install and activate the plugin we created called Insert Post Ads. Upon activation, the plugin will add a new menu item called Post Ads.
Click Post Ads »Add New . On the next screen, simply add the name of your ad for identification purposes, enter the ad code, and select the paragraph in which you want the ad code to appear. Once done just click publish.
Next you want to go to Post Ads »Settings to select the post types you want to show your ads on, such as posts, pages, and custom post types.
Now, if you don't like using the plugin, and want to do it in a coded way, follow the instructions below.
Open your theme functions.php or a site-specific plugin file and paste the following code:
'; $agraphs = explode ($ closing_p, $ content); foreach ($ párrafos como $ índice => $ párrafo) si (recortar ($ párrafo)) $ párrafos [$ índice]. = $ closing_p; if ($ paragraph_id == $ index + 1) $ párrafos [$ index]. = $ inserción; return implode (", $ apartados);
To add your ad code, simply edit the value of $ad_code where it says "Ad code goes here" on line 9. Once you do that, you're done. To change the paragraph number, simply change the number 2 to another paragraph number on line 12.
We hope this article helped you insert ads within your WordPress post content.
If you liked this article, please consider subscribing to our YouTube channel and join us on Twitter.
Thanks to @GaryJ for improving the code we had.