Archived topic
Creating reserve space for Google Ads to avoid layout shift and LCP isssue
11 replies · Started by surendra1506 on March 20, 2022
Hi team,
I own an educational site Classmate4u.com. I want to reserve space by creating containers for ads.
I am facing layout shift issues and also LCP issues on my site since ads are pushing down the content.
Also, the container needs to be responsive so that they adjust according to the screen (mobile, desktop & tablet).
Please help me to achieve that.
Hi Surendra,
To do as such, you may add your Ad’s script as such:
<div class="my-advert">
<!-- you ad script here -->
</div>
Then, you may use custom CSS to set a minimum height to the container:
.my-advert {
min-height: 280px;
}
You’re sidebar advertisement has a different height. Thus you would need to set a different class name. For instance:
<div class="sidebar-advert">
<!-- you sidebar ad script here -->
</div>
CSS:
.sidebar-advert {
min-height: 1272px;
}
Here is an article with regards to adding CSS: https://docs.generatepress.com/article/adding-css/#additional-css
Adding the CSS through additional CSS should work.
Hope this helps! :)
Hi, Fernando
I had implemented what you have instructed over here.
But I am still facing layout shift issues. Request to check at your end.
I don't think that the code had done anything in this regard.
Thanks in Advance
Also, I am using Hook elements for Google Adsense Ads implementation on my site.
Hi there,
can you disable the SG optimiser as I cannot see the CSS that Fernando provided on your site
Hi David,
I had pasted it in the Additional CSS section provided in the Theme Customize setting.
However, I had removed the code
That, I thought might be causing some issues or making the code invalid.
Thanks
Hi there,
I can see the CSS has been added to your site, but I don't see the CSS class sidebar-advert or my-advert has been added to your ads.
Can you make sure your ads code is like this?
<div class="my-advert">
<!-- you ad script here -->
</div>
Thankyou all, The CLS issue for site has been resolved.
Lastly, sometime it is showing LCP for title of the page.
Request, please help to make title also responsive for mobile,desktop and tablets.
Thanks
Hi Surendra,
I can’t seem to replicate the issue from my end after testing on Desktop and Mobile through Lighthouse:
https://share.getcloudapp.com/JruObnel
https://share.getcloudapp.com/Z4u7Lr9l
Looking at this response by David about LCP would be insightful: https://generatepress.com/forums/topic/largest-contentful-paint-on-h1-issue/#post-1345248
Hope this clarifies. :)
Thank you so much Fernando, Ying, and David everything is resolved.
You’re welcome Surendra! We’re glad to be of assistance. Feel free to reach out anytime if assistance with anything else is needed. :)
Sure