我在我的网站上实现了“跳到内容”链接并将其隐藏在屏幕之外(除非
:focus
ed)。但是,我注意到在一些我没有明确定义元描述的页面上,Google 在搜索结果中选择“跳到内容”作为其预览片段。
有没有办法格式化或标记不应在搜索片段中使用的文本?我的案例是跳到内容链接,但我可以想象其他类似的需求。但是,在这种情况下,它必须保持可访问(因此没有
display:none
等)。
我想我正在寻找的是
rel="nofollow"
的某个版本,但是是下一个版本,而不仅仅是链接。
tl;dr:“跳到内容”链接出现在搜索片段中。这不是我们想要的。
我认为一般的Google搜索没有这样的方法。
Google 允许其 Google Search Appliance 和 Google Mini 产品的客户通过在 HTML 注释中使用
googleoff
和 googleon
来说明搜索时应忽略哪些内容;请参阅从索引中排除不需要的文本。 但是 当然,这不适用于公共 Google 搜索。
我认为防止该问题的最佳方法是使用
meta
description
: http://support.google.com/webmasters/bin/answer.py?hl=en&answer=79812
<meta name="description" content="A description of the page" />
它必须保持可访问(因此不显示:无等)
好吧,如果您可以使用 JavaScript,您仍然可以在 div 或 span 标记中使用
style="display:none"
并将以下内容添加到您的 JS 文件中:
$(document).ready(function() {
document.getElementById('skip').style.display = "block";
//Or shorter with jQuery
$('#skip').show(); //Alternatively: fadeIn()
});
从 2021 年左右开始,您可以排除 Google 代码片段中包含的文本。您可以在
data-nosnippet
、div
或 span
元素上使用 section
html 标签。看起来像这样:
<div>Show this
<span data-nosnippet>Never show this in the snippet, but otherwise display it normally</span>
</div>
文档位于 https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#data-nosnippet-attr