How to display ads over content in WordPress
You can display an ad over WordPress content with a fixed-position HTML element and CSS, added to one page or site-wide through a child theme. For timed triggers, device targeting, close buttons and responsive rules, a plugin is usually the safer route.
- 01Choose the overlay type
- 02Prepare the advert content
- 03Add one overlay manually
- 04Make it site-wide safely
- 05Test the overlay behaviour
- 06Use a plugin for advanced control
What you need
- A WordPress site with administrator access
- Ad HTML, image or approved advertising code
- A child theme or safe custom-code method for site-wide changes
- A mobile and desktop browser for testing
Choose the overlay type
Decide whether the advert should cover the viewport, sit in a bottom corner, appear over an image or video, or show only after a click or scroll. A fixed overlay remains attached to the browser window; an absolute overlay stays positioned inside a particular content container.
If you are using Google AdSense, consider its built-in anchor format rather than creating an unofficial sticky format. Anchor ads are designed to stick to the edge of the screen and include a dismissal control.
Prepare the advert content
Create the advert with a clear label, a visible close button and a responsive width. Keep the creative small enough that it does not hide navigation, the article heading or the main action on a phone.
For an image, use an optimised file and a meaningful alternative description. For third-party advertising code, paste the code supplied by the advertising network rather than rewriting its script.
Add one overlay manually
For a single page, add a Custom HTML block and place the advert markup in it. Give the outer element a unique class such as site-ad-overlay, then add CSS that uses position: fixed, a suitable z-index, a maximum width and spacing from the screen edges.
A typical layout uses a close button inside the wrapper and CSS such as inset: auto 1rem 1rem for a bottom placement. Add the JavaScript needed to hide the wrapper when the button is clicked. WordPress may remove script or iframe markup for users without the required unfiltered HTML capability, so check the saved block and the front end rather than assuming it was retained.
Make it site-wide safely
For a site-wide overlay, place the output in a child theme or a site-specific code plugin instead of editing the parent theme. WordPress themes commonly expose the wp_footer action immediately before the closing body tag, which is a suitable place to print the overlay markup or load its supporting code.
Limit the output to the pages where the advert is allowed. Add conditions for posts, pages, categories, devices or logged-in users as needed. A Friday-afternoon failure here is displaying the advert twice because it was added both to the template and to a footer injection field.
Test the overlay behaviour
Check the advert on a narrow phone screen, a tablet and a desktop. Confirm that the close button can be reached with a finger and keyboard, the advert does not cover the cookie notice or navigation, and the page remains usable after the overlay is dismissed.
Clear page and browser caches after changing the code. Also test a cached page and an ad blocker, because delayed third-party scripts can leave an empty box, shift the layout or make a close button appear before the advert has loaded.
Use a plugin for advanced control
The manual method is fine for one simple advert, but a plugin is more practical when you need multiple creatives, page targeting, scroll or click triggers, responsive positioning, animations, frequency controls or a dashboard for non-developers. Ad insertion tools commonly support placements before, after or inside content, while overlay-specific tools add floating behaviour and triggers.
Ad Overlay Anything is worth considering when the advert must sit over text, images or videos and respond to user behaviour. It provides responsive positioning, trigger options and integrations with common page builders, so you can manage the overlay without maintaining custom theme code.
Let Ad Overlay Anything do it
Adds responsive ad overlays to videos, images, and text with behavior-based triggers when inline visibility matters.
Sources
- support.google.com /adsense/answer/15484692?hl=en&utm_source=openai
- wordpress.org /documentation/article/custom-html/?utm_source=openai
- developer.wordpress.org /reference/hooks/wp_footer/?utm_source=openai
- wordpress.org /plugins/init-ad-engine/?utm_source=openai
- wordpress.org /plugins/wp-insert/?utm_source=openai
Questions
- Can I display an ad over WordPress content without a plugin?
- Yes, a simple overlay can be built with HTML, CSS and optional JavaScript in a Custom HTML block or a child theme. Use fixed positioning for a viewport overlay and add a close control yourself. This is suitable for one or two placements, but it becomes difficult to manage when you need targeting, rotation, frequency limits or different mobile and desktop versions.
- What is the difference between an overlay and an ad inside content?
- An overlay sits above the page, usually with fixed or absolute positioning, while an in-content advert occupies a position between paragraphs or blocks. Overlays attract attention but can obstruct reading, so use them sparingly. In-content placement is usually less intrusive and can be inserted manually or through an ad insertion plugin with paragraph-based rules.
- Why does my WordPress ad overlay disappear or show as plain text?
- The code may have been sanitised, the theme may not include the footer hook, or a cache or optimisation tool may have altered the script. WordPress can remove script and iframe markup for users without the required capability, and plugins relying on the footer action cannot render there if the theme omits it. Check the saved markup, theme footer and browser console.
- How do I stop an overlay ad covering mobile content?
- Use responsive CSS with a maximum width, safe margins and a smaller mobile height, then test at narrow viewport sizes. Keep a visible close button outside the main creative and avoid placing the overlay over navigation, cookie controls or checkout actions. If you use AdSense, its anchor format includes responsive behaviour and dismissal controls intended for edge-of-screen placements.