I'm using Wordpress (based on php, for those who do not know) and would like to insert a content every x paragraphs. My goal is to put a html or javascript code (an ad from Adsense or direct advertising, for example) every 5 paragraphs (in the middle of the article that the user is reading).
I found this post that presents a solution to this problem in javascript, but for years I stopped programming so I could not make it work on my blog.
Note: The code should add content only to text that is inside the entry-content div. This is the div where the post that the user reads is located.
Edit: The use of ready-made plugins is out of the question.
Edit 2: This is the code I found and partially solved my problem. It does not work for me because with it I can only use text, I can not use an html code, call a page in php or insert a javascript
$('p').each(function(i) {
var pos = i + 1;
if (pos % 3 == 0) {
$('<div/>', {
class: 'anuncio',
text: 'Div inserida!'
}).insertAfter(this);
}
});
Edit 3: This is the javascript code (adsense ad) that I need to insert into the page. It is against the Google Adsense rules to even change this code minimally
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-format="fluid"
data-ad-layout="in-article"
data-ad-client="ca-pub-6765322619356148"
data-ad-slot="6356279518"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>