Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davetk's avatar
Level 1

Javascript code is not executing when using livewire component

I want to execute a code in component but the component only loads, iframe, img tag html, when i place script tag code then livewire is able to retrieve the code but script are not executed,

showads.blade.php

<div>
    @if(!$isPremium)
    <div id="mold-container">
        {!! $loadAds !!}
    </div>
    @endif
</div>

ShowAds.php

show-app.blade.php

<main>
    <div class="page-header bg-sixth">
        <div class="container">
           <div class="row">
              <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                 <div class="page-caption" style="text-align: center;">
                    <h1 style="color: #FFF;">APP Name</h1>
                    <hr style="margin-top: 0px;margin-bottom: 30px;border-top-width: 2px;">
                    <div class="col-lg-12 col-xl-12">
                       <div class="banner-frame text-center">

                       </div>
                    </div>
                    <x-country-holder panel="c" lazy/>
                 </div>
              </div>
           </div>
        </div>
      </div>
      <div class="container">
         <div class="row">
            <div class="text-center mt-3">
               <livewire:ShowAds ads_code="ads_code_3" lazy/>
            </div>
           
         </div>
      </div>
</main>

i am successfully getting value of ads code of front end but the ads is not assigned any space in front end hence no ads was seen, i tried to assign min-height property but that also didn't seem to work

i want to show ads code like

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- InBetween List -->
            <ins class="adsbygoogle"
                 style="display:block"
                 data-ad-client="ca-pub-PUB_ID"
                 data-ad-slot="SLOT_ID"
                 data-ad-format="auto"
                 data-full-width-responsive="true"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>

ads code are retrieved on front-end but javascript is not loading ads, but when i replace '<livewire:ShowAds ads_code="ads_code_3" lazy/>' directly with above adsense ad code then ads are being displayed.

any suggestion would be really helpful

0 likes
6 replies
davetk's avatar
Level 1

Some please help i am unable to understand the reason for this issue, when i store or content in database then it gets loads and executed on livewire component but when i am using any code then it is loading the script but not executing the script

Snapey's avatar

how are you calling the script after you inject it into the page? It wont run on its own?

davetk's avatar
Level 1

@Snapey thank you for replying sir, i don't know how to call the script after injecting in page in laravel, can you please provide some brief info on how to achieve this.

I tried to call using custom javascript function but that didn't worked because i don't know how to sync lazy load with my custom javascript to call the script.

Kindly guide me how to achieve this.

davetk's avatar
Level 1

@Snapey I am using this ShowAds LiveWire Component on a, ShowGenerator Livewire Component like this,

show-generator.blade.php

<div class="container">
         <div class="row">
            <div class="text-center mt-3">
               <livewire:ShowAds ads_code="ads_code_3" lazy/>
            </div>
         </div>
      </div>

I tried every possible ways i have known, but tag ads are not loading, kindly provide some code snippet to get this to work

davetk's avatar
Level 1

Kindly anyone suggest me how to fix it

Please or to participate in this conversation.