Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted March 15, 20213 yr Hey there! I have several advertisements blocks and also blocks widgets that can load these advertisements. I was wondering... Can I use the {block="myblock"} or {advertisement="myad"} inside a page content? How do you resolve this thing? Cheers, Ibai
March 15, 20213 yr use JS to inject your ad code into post via something like $("article.cPost:eq(0) [data-role='commentContent'] p:eq(2)").after("your code here") above shows ad in first post, after 3rd paragraph Edited March 15, 20213 yr by Eudemon
March 15, 20213 yr Author 10 minutes ago, Eudemon said: use JS to inject your ad code into post via something like $("article.cPost:eq(0) [data-role='commentContent'] p:eq(2)").after("your code here") above shows ad in first post, after 3rd paragraph Hey thanks @Eudemon! I understand the code. However, how can I embed adsense code? Just copy and paste their code there escaping the quote mark? Would that work?
March 15, 20213 yr Solution 7 minutes ago, Ibai said: how can I embed adsense code? Just copy and paste their code there escaping the quote mark? Would that work? yes const yoyo = '<b>tofu is life</b>' $("article.cPost:eq(0) [data-role='commentContent'] p:eq(2)").after(yoyo) Edited March 15, 20213 yr by Eudemon
March 16, 20213 yr Author Thanks for the idea @Eudemon This is my final code for long articles, which I inserted in a advertisement block and then I load wherever I want with {advertisement="myad"} <script> const yoyo = '<ins class="adsbygoogle"........ADSENSE INS TAG.......></ins>'; window.addEventListener('load', function () { if($("article:eq(0) p").size()>10){ $("article:eq(0) p:eq(8)").after(yoyo); (adsbygoogle = window.adsbygoogle || []).push({}); } if($("article:eq(0) p").size()>25){ $("article:eq(0) p:eq(20)").after(yoyo); (adsbygoogle = window.adsbygoogle || []).push({}); } if($("article:eq(0) p").size()>50){ $("article:eq(0) p:eq(43)").after(yoyo); (adsbygoogle = window.adsbygoogle || []).push({}); } if($("article:eq(0) p").size()>75){ $("article:eq(0) p:eq(69)").after(yoyo); (adsbygoogle = window.adsbygoogle || []).push({}); } if($("article:eq(0) p").size()>100){ $("article:eq(0) p:eq(98)").after(yoyo); (adsbygoogle = window.adsbygoogle || []).push({}); } if($("article:eq(0) p").size()>130){ $("article:eq(0) p:eq(128)").after(yoyo); (adsbygoogle = window.adsbygoogle || []).push({}); } if($("article:eq(0) p").size()>170){ $("article:eq(0) p:eq(167)").after(yoyo); (adsbygoogle = window.adsbygoogle || []).push({}); } }); </script>
March 16, 20213 yr just few point of improvement base on your code you can just have one of this, this pushes all adsbygoogle globally (adsbygoogle = window.adsbygoogle || []).push({}); you can also store `article:eq(0)` to a variable then select whatever within it, so you don't have to repeat the same code, you can also shorten all the statements above with one line tenant condition Edited March 16, 20213 yr by Eudemon
March 17, 20213 yr Author 11 hours ago, Eudemon said: just few point of improvement base on your code you can just have one of this, this pushes all adsbygoogle globally (adsbygoogle = window.adsbygoogle || []).push({}); you can also store `article:eq(0)` to a variable then select whatever within it, so you don't have to repeat the same code, you can also shorten all the statements above with one line tenant condition Hey Eudemon, Thanks for your tips. Yeah, definitely the code was optimizable, that was the first approach. I applied your second suggestion. However, are you sure that one line of push is enough? I've been testing and when I code just one line of push, it shows only the last ad. I put back that line for each ad and now is showing all of them. Thanks for your support!
October 22, 20213 yr On 3/17/2021 at 4:50 AM, Ibai said: Hey Eudemon, Thanks for your tips. Yeah, definitely the code was optimizable, that was the first approach. I applied your second suggestion. However, are you sure that one line of push is enough? I've been testing and when I code just one line of push, it shows only the last ad. I put back that line for each ad and now is showing all of them. Thanks for your support! It's not working more 😞
October 22, 20213 yr I have move this topic to our developer connection forum, as this isnt really a built in function of the platform.
October 22, 20213 yr 2 hours ago, Marc Stridgen said: I have move this topic to our developer connection forum, as this isnt really a built in function of the platform. Please, allow this function by default. This help us a lot if we have a big topics.