Home › Forums › Support › Strange problem with an ad in element on archive page! (Footer in the middle)
- This topic has 19 replies, 3 voices, and was last updated 1 year, 3 months ago by
Tom.
-
AuthorPosts
-
June 20, 2022 at 2:42 am #2258628
Dieter
When I place an Adsense ad in an element (Block hook with a GB-Container and html-block) that is included on archive pages, the page footer is in the middle of the page.
Screenshot:
The page footer is also included with an element (element type: site footer).
I have now included this element only on the following archive page, so you can see the problem:
(link removed)I never had such a problem before and I am at a loss. Any ideas?
Also for info:
I am using wp-rocket but all optimizations are off. Even if I exclude this page from the cache the error is there. The error does not always occur, but very often (just reload the page a few times).Thanks a lot for help.
Best regards
June 20, 2022 at 4:02 am #2258723David
StaffCustomer SupportHi there,
i believe the issue is arising from the inline-styles that are being injected into the Theme Elements. See here:
Many of the theme elements have had the
height: auto !important;
style added to them.
Including thegenerate-columns-container
whose height cannot be auto.You need to find and eliminate which plugin or script is adding those inline styles.
June 20, 2022 at 6:15 am #2258856Dieter
Hi David,
this is really strange but thanks for looking into it.
I have the Health Check & Troubleshooting plugin installed and have disabled everything except Generatepress and Generateblocks in troubleshooting mode.
But the inline styles are still inserted. I thought maybe it was Toolset but the archive pages are not touched by Toolset and when Toolset is disabled it doesn’t work either.This also only happens in archive pages when I have inserted the element with the Adsense code.
On all other archive pages without this element nothing of these inline styles is to be seen far and wide.In my local dev-site there is also nothing to see. But there I can’t test any Adsense code either. But elements with image dummies work fine.
Maybe it’s not so bad, because the website was just accepted by Mediavine and soon the advertising will be changed.
I’m just a little unsettled since I just switched from Astra yesterday and didn’t have a problem before.
However, Astra has other little problems and that’s why I really wanted to change the theme before switching to Mediavine to have a solid base.I guess I’ll have to keep thinking.
June 20, 2022 at 6:52 am #2258896David
StaffCustomer SupportI get the impression the adsense code is adding those inline styles.
What if you disable the Masonry option in Customizer > Layout > Blog ? Is that an option ?
June 20, 2022 at 7:33 am #2258943Dieter
Thanks David!
It really seems to be. I found a way to test it locally.
When I disable the masonry layout everything seems to be ok.
So I would disable masonry for now.
Do you see any way that this problem can be addressed in the future?
June 20, 2022 at 7:43 am #2258963David
StaffCustomer SupportThe issue comes from that inline style of
height: auto
being added to the columns container.
Masonry runs scripts to calculate the height and position of each position. And part of that includes setting the height of the columns container. And that inline style is breaking it.Are you inserting adverts inside the Columns Container? ie. in between posts ?
June 20, 2022 at 8:34 am #2259201Dieter
Currently, no ads are inserted between them in the archive. The adsense auto ads are also currently off as there have been issues as well.
I have now disabled masonry and currently it works with a placed element. However, I’ve never had problems like this before and I’m a little unsure what else is coming up.
June 20, 2022 at 8:57 am #2259243David
StaffCustomer SupportYou need to find what is adding the
height: auto !important;
to the themes HTML. It can cause these kinds of problems.
Could you create a staging site and then you can remove plugins and scripts to see which one is adding that inline style.June 20, 2022 at 12:48 pm #2259475Dieter
It is clear. No plugin is to blame – it’s the Adsense script.
The Adsense script inserts these inline styles. I also see this on other sites of mine and others, but there it does not have a negative effect.There are also some others on the net that have bigger problems with it.
I think Google has been doing this for a while, but this is the first time I’ve encountered this problem. Not nice what Google does there.
I found out, that with a responsive display ad this paramenter is significantly involved:
data-ad-format="auto"
If this is removed, then the inline styles are not inserted. Probably there are then other problems with the ad display. Maybe this can be adjusted with a detailed adjustment of the ad code. But I have not tested that yet.Other people counter this with MutationObserver. But I have never done that.
Anyway, I now know where the error comes from.
Thanks a lot 🙂
June 21, 2022 at 3:23 am #2259876David
StaffCustomer SupportAha – ok so i found some posts on the mutationObserver
<script> // based on code found at: // https://stackoverflow.com/questions/55695667/adsense-injecting-style-tag-into-my-page-in-chrome var flex = document.getElementsByClassName('generate-columns-container')[0]; const observer = new MutationObserver(function (mutations, observer) { flex.style.height = ""; }); observer.observe(flex, { attributes: true, attributeFilter: ['style'] }); </script>
This line:
var flex = document.getElementsByClassName('generate-columns-container')[0];
i added ourgenerate-columns-container
class so its being observed.You can use a Hook Element to add the
<script>
into either thewp_head
or thewp_footer
.For reference the script came from this post:
June 21, 2022 at 7:31 am #2260058Dieter
Nice find @David!
But I get this error message in Firefox Console:
Uncaught TypeError: MutationObserver.observe: Argument 1 is not an object.
Chrome displays this:
Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
June 21, 2022 at 7:39 am #2260067David
StaffCustomer SupportIs that the case if you add it the
wp_footer
hook?
As that error simply means that thegenerate-columns-container
element wasn’t found when the script fired.June 21, 2022 at 7:55 am #2260241Dieter
OK,
wp_footer
hook works – the error is gone – height: auto !important is also gone but now the height is missing completely.
Now looks like this:
<div class="generate-columns-container masonry-container" style="position: relative;">
June 21, 2022 at 8:08 am #2260257David
StaffCustomer SupportYeah – thats an issue, i tried refactoring the code to unmount the mutationObserver after it removes the
height
property so it can leave GPs Masonry script to do its thing, but the timing is out.Do you have this set up on an archive with the masonry setting on?
June 21, 2022 at 8:13 am #2260259Dieter
Yes for an archive with masonry because without masonry everything is ok so far.
-
AuthorPosts
- You must be logged in to reply to this topic.