Archived topic
How to move "Back to Top Button" up when AdSense displays an anchor ad?
3 replies · Started by Trevor on April 4, 2022
Hi, The "Back to Top Button" is covered when google AdSense displays a bottom anchor ad. The footer bar gets automatically bumped up to account for the ad but the sticky back to top button doesn't get moved accordingly.
Is there a way to have this move only if an anchor ad loads?
I know the crude solution is to just move it up the page so it's always way off the bottom (eg: bottom: 150px;) but I would prefer to keep it tucked down in the corner when there's no ad shown.
Any ideas appreciated.
Hi Trevor,
You can try to create a script checking whether there is an advertisement loaded.
For instance, you may check if data-ad-status="filled" or data-ad-status="unfilled”: https://support.google.com/adsense/answer/10762946?hl=en
You can also try placing the ad inside a div as such: https://generatepress.com/forums/topic/add-padding-on-top-of-navigation/#:~:text=8%3A29%20pm-,%232173072,-EDIT%20%7C%20MOVE%20%7C%20SPLIT
Then, through your script, check if the div contains an ad: https://gomakethings.com/how-to-check-if-an-element-contains-another-one-with-the-vanilla-js-node.contains-method/
After which, change the position of the Back-to-top button based on this: https://stackoverflow.com/questions/2214387/setting-top-and-left-css-attributes
You can add scripts through a Hook Element. Try hooking it after the ad's script.
Hope this helps! :)
Hi Fernando,
Thanks for the info. Sorry, I didn't mean to just leave this open for months!
What you suggest I think would work after looking into it a bit. I've decided to give up on it though based on the roi on the time required to figure it out.
If anyone else figures out the final solution I'd love to see it. For now I'll just bump the button up the page regardless of an ad existing or not.
I see. You’re welcome Trevor!