DEV Community

Stefan Judis
Stefan Judis

Posted on • Originally published at stefanjudis.com

TIL — How to exclude elements from being shown in Google Search results

Let's look at what happens when I google myself.

Developer, writer and speaker | Stefan Judis Web Development — Heyooo, I'm Stefan! I write and speak about web stuff. · New on the blog · My Weekly Newsetter · Most popular in the last 30 days · Hacker News Hits.

Of course, I know how my site is structured, and I can tell that Google displays my site's title and the description includes some of the root page's headlines. The description is not the worst, but it certainly could be better.

Is there a way to exclude elements from being shown in the Google snippet?

Today I learned that there is! And the solution is based on an HTML data attribute: data-nosnippet. Here's the example snippet from the Google Search Central docs:



<p>This text can be shown in a snippet
<span data-nosnippet>and this part would not be shown</span>.</p>

<div data-nosnippet>not in snippet</div>
<div data-nosnippet="true">also not in snippet</div>
<div data-nosnippet="false">also not in snippet</div>


Enter fullscreen mode Exit fullscreen mode

data-nosnippet works on div, span and section elements, and it doesn't care what value you'll give it. data-nosnippet="true" and data-nosnippet="false" have the same result — signaling that this element shouldn't pop up in the Google Search results. Nice!

If you're unhappy with the search results, add some juicy data attributes now. But remember to trigger a reindex in the Search Console. Otherwise, it might take a while until your changes have an effect.

Top comments (0)