I've started running Google AdSense on this blog.
Between writing articles, building web apps, and developing WordPress plugins, I have ongoing server and domain expenses. A little advertising revenue would help cover those costs. But I don't want ads to make the site harder to use, so the plan is to keep them modest and primarily on blog articles, rather than on the homepage, product pages, or web apps themselves.
I've also outlined my approach on the advertising and disclosures page.
I'm using AdSense Auto ads so I don't have to define ad placements for every article. It's convenient, but I noticed a problem shortly after enabling it.
Ads appearing inside tables
I often use tables to compare product features and pricing. Sometimes Auto ads would appear inside those tables.
A table conveys information through the relationships between its rows and columns. Inserting an ad in the middle doesn't just look bad; it disrupts those relationships. I'd also rather not see code blocks, lists, or figures and their captions interrupted by advertising.
So I looked into ways to prevent these placements while continuing to use Auto ads.
Start with placement and ad load settings in AdSense
As of December 2026, the Auto ads settings let you enable or disable individual formats. Advanced banner settings also let you limit the number of ads and set a minimum distance between them.
I've enabled only banner and side rail ads, leaving anchor ads, vignette ads, and ad intents disabled. My general rule is that a few ads between sections of an article are fine, but formats that noticeably degrade the user experience aren't.
I've also disabled Auto optimize, which lets Google test ad settings. Optimizing revenue doesn't necessarily account for how intrusive the ads feel. I'd rather decide on formats and ad load myself, with the site's usability in mind.
AdSense also offers excluded areas. Open the site's editing screen under Ads and select areas in the preview where you don't want in-page ads to appear.
Although exclusions can apply to pages with similar layouts, selecting every area that varies between articles in a preview is impractical. I'd like to be able to enter a CSS selector such as table and exclude matching elements across the entire site.
Using HTML attributes to discourage ad placement
According to an analysis of the AdSense delivery script, a version retrieved in October 2026 included logic that reads a data-no-auto-ads attribute and recognizes the following values:
| Value | Intended exclusion |
|---|---|
inside | Inside the element |
before | Before the element |
after | After the element |
all | Inside, before, and after |
Multiple values can be separated by |. I chose inside because I want the space before and after a table to remain eligible for ads.
I haven't found
data-no-auto-adsin Google's public documentation. It comes from a third-party analysis of the delivery script, and I haven't verified its effectiveness in my own environment. There is no guarantee it will remain available.
For sites using ad intents, I've also included google-anno-skip, a class documented by Google.
<table data-no-auto-ads="inside" class="google-anno-skip">
<!-- Table content -->
</table>
The class is intended to prevent ad intent links and chips from being inserted. It does not exclude ordinary banner ads.
Rather than editing each element manually, you can add these attributes in PHP on WordPress or use JavaScript on other sites.
Adding the attributes through a WordPress theme
Adding attributes by hand every time I write an article would be tedious, so I handle it centrally in the theme's functions.php.
The WP_HTML_Tag_Processor, introduced in WordPress 6.2, lets you modify HTML tags without resorting to regular expressions or adding attributes after rendering with JavaScript.
function happas_blog_exclude_structured_content_from_auto_ads(string $content): string
{
if ($content === '' || is_admin() || is_feed() || wp_is_json_request()) {
return $content;
}
$html = new WP_HTML_Tag_Processor($content);
$excluded_tags = array(
'TABLE', 'PRE', 'CODE', 'FIGURE', 'BLOCKQUOTE',
'UL', 'OL', 'NAV', 'FORM', 'DETAILS'
);
while ($html->next_tag()) {
if (! in_array($html->get_tag(), $excluded_tags, true)) {
continue;
}
$exclusion = $html->get_attribute('data-no-auto-ads');
$exclusions = is_string($exclusion) ? explode('|', $exclusion) : array();
if (! in_array('all', $exclusions, true)) {
$exclusions[] = 'inside';
$exclusions = array_unique(array_diff($exclusions, array('')));
$html->set_attribute('data-no-auto-ads', implode('|', $exclusions));
}
$html->add_class('google-anno-skip');
}
return $html->get_updated_html();
}
add_filter('the_content', 'happas_blog_exclude_structured_content_from_auto_ads', 99);
The target elements include code, lists, quotations, and forms as well as tables. The code adds inside without removing existing exclusions. If all is already present, the value is left unchanged.
The the_content filter runs at priority 99, after normal block rendering. It doesn't modify articles stored in the database. It only affects content that passes through this filter, so it doesn't protect the entire template, including headers and sidebars.
I use a custom WordPress theme for this blog, but I keep advertising-specific behavior in its child theme rather than the parent theme.
A JavaScript alternative for other sites
If you can modify the templates or build process that generates your HTML, adding the attributes at that stage is preferable. If the existing HTML is difficult to change, you can add them in one pass with JavaScript instead.
function excludeAutoAds() {
const selector = 'table, pre, code, figure, blockquote, ul, ol, nav, form, details';
document.querySelectorAll(selector).forEach((element) => {
const exclusions = (element.getAttribute('data-no-auto-ads') || '')
.split('|').filter(Boolean);
if (!exclusions.includes('all')) {
exclusions.push('inside');
element.setAttribute('data-no-auto-ads', [...new Set(exclusions)].join('|'));
}
element.classList.add('google-anno-skip');
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', excludeAutoAds, { once: true });
} else {
excludeAutoAds();
}
Once the DOM is ready, the script selects matching elements and adds the attributes. If you only want to target tables and forms, change the selector to table, form.
However, DOMContentLoaded doesn't wait for asynchronous scripts to finish, and AdSense isn't guaranteed to wait for the DOM to be ready. The attributes need to be present before ad placement is evaluated. If you can't control that execution order, I recommend adding the attributes during HTML generation or using the excluded areas feature instead.
Adjusting the spacing around ads
Adding space between ads and content
I also use CSS to add a bottom margin to the outer Auto ads container.
.entry-content .google-auto-placed {
margin-bottom: 1rem;
}
Adjust the margin and the .entry-content selector to match your site's design and HTML structure.
Removing gaps left by unfilled ads
An ad request may return no ad, leaving an empty slot. Google documents a CSS rule for hiding unfilled ad units.
ins.adsbygoogle[data-ad-status="unfilled"] {
display: none !important;
}
I also remove the margin from containers that have an unfilled ad unit as a direct child.
.entry-content .google-auto-placed:has(
> ins.adsbygoogle[data-ad-status="unfilled"]
) {
margin-block: 0;
}
Neither rule hides ads with a filled status or slots Google has repurposed with an unfill-optimized status.
Google may deliberately leave unfilled slots visible within the viewport. Collapsing a slot can move content and affect CLS (Cumulative Layout Shift), so eliminating every blank space doesn't necessarily make a page more comfortable to read.
These adjustments are made to the site's HTML and CSS without modifying the AdSense delivery script itself.
Reference: Google's rules on modifying AdSense ad code.
Auto ads should respect the structure of the content
The ideal ad placement won't be the same for every website. Still, I'd like Auto ads to recognize the meaning of HTML elements and leave cohesive blocks of content intact by default. Auto ads have been around for quite a while, and I'd imagine publishers have given similar feedback over the years.
The reason I use Auto ads is to avoid managing placements individually. If doing so means sacrificing readability or manually fixing the places where ads have appeared, it rather defeats the purpose.







Comments