Ibai Posted March 15, 2021 Posted March 15, 2021 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
Eudemon Posted March 15, 2021 Posted March 15, 2021 (edited) 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, 2021 by Eudemon SeNioR- 1
Ibai Posted March 15, 2021 Author Posted March 15, 2021 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?
Solution Eudemon Posted March 15, 2021 Solution Posted March 15, 2021 (edited) 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, 2021 by Eudemon Ibai and cocoliso 1 1
Ibai Posted March 16, 2021 Author Posted March 16, 2021 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>
Eudemon Posted March 16, 2021 Posted March 16, 2021 (edited) 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, 2021 by Eudemon Ibai 1
Ibai Posted March 17, 2021 Author Posted March 17, 2021 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!
Eudemon Posted March 17, 2021 Posted March 17, 2021 that's weird, i just tried it myself and it worked for me ...
403 - Forbiddeen Posted October 22, 2021 Posted October 22, 2021 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 😞
Marc Posted October 22, 2021 Posted October 22, 2021 I have move this topic to our developer connection forum, as this isnt really a built in function of the platform.
403 - Forbiddeen Posted October 22, 2021 Posted October 22, 2021 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. Ibai 1
Recommended Posts