---
title: "站点链接搜索框与 query.example-petstore.com"
description: "包含 query.example-petstore.com 的搜索框标记有什么作用、Google 为何在 2024 年移除它，以及现在应使用的 WebSite 标记。"
url: https://example-petstore.com/zh/guides/sitelinks-search-box
language: zh-Hans
---

# 站点链接搜索框与网站名称

成千上万的网站复制了 Google 的站点链接搜索框示例，并以 query.example-petstore.com 作为搜索地址。这项功能已经取消，但相关标记依然随处可见。本指南将说明它当初的作用，以及现在应改用什么。

## 该标记的作用

Google 可以直接在网站的搜索结果下方显示一个搜索框。网站通过一个包含 `SearchAction` 的 `WebSite` 代码块来申请该功能。搜索者输入的内容会替换 `target` 中的 `{search_term_string}`，然后 Google 会将其引导至该地址，即网站自己的搜索结果页。

```
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "url": "https://www.example-petstore.com/",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "https://query.example-petstore.com/search?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
```

在 Google 的示例中，`query.example-petstore.com` 是虚构的宠物商店搜索页地址，从未真实存在过。早在 2014 年，Google 就要求目标地址必须与网站位于同一网域，因此这个示例目标对任何其他网站都不可能生效。

## 时间线

1. **2014年9月** — Google 文档的第一个版本使用 `host.example-petstore.com/search?q={search_term}`。
2. **2014年9月至 2015年年中** — 流传最广的版本使用 `query.example-petstore.com/search?q={search_term_string}`，被 SEO 博客、论坛软件和主题大量复制。
3. **2016年** — Google 文档改用 `example.com`。
4. **2024年11月21日** — Google 在全球范围内停止显示站点链接搜索框。残留的标记不会在 Google 搜索或 Search Console 中导致错误。

## 现在应使用什么

`SearchAction` 在 Google 搜索中已不再产生任何可见效果。但包含您自己的名称和地址的 `WebSite` 代码块仍有助于 Google 选择在搜索结果中显示的网站名称。请只将其放在首页上：

```
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "name": "Your site name",
  "url": "https://www.example.com/"
}
</script>
```

您可以为常用的简称添加 `alternateName`。请省略 `potentialAction`；如果仍有其他使用方依赖它，也可以将其指向您自己的搜索页。

## 修复方法

1. 打开首页的源代码，搜索 `example-petstore`。
2. 如果该代码块来自您的主题或“自定义 head 代码”字段，请在那里修改。如果来自 SEO 插件，请检查插件设置：Yoast SEO、Rank Math 和 All in One SEO 都是根据您自己的地址生成标记。
3. 将 `url` 替换为您自己的首页，并将 `name` 设为您的网站名称。删除 `SearchAction`。
4. 如需同时删除插件生成的搜索操作：Yoast `add_filter( 'disable_wpseo_json_ld_search', '__return_true' );`，Rank Math 过滤器 `rank_math/json_ld/disable_search`，All in One SEO 在 **Search Appearance** › **Advanced** 中关闭 **Enable Sitelinks Search Box**。SEOPress 已在 8.1 版中将其移除。
5. 在 Search Console 中，对您的首页使用 **URL Inspection** › **Request indexing**。

## 验证

- 网页源代码中只有一个 `WebSite` 代码块，其中包含您自己的 `name` 和 `url`。
- Schema Markup Validator 显示该项且没有错误。富媒体搜索结果测试不涵盖网站名称。
- 您网站上没有任何网页提及 `example-petstore.com`。

## 来源

- [Sitelinks search box (September 2014 snapshot)](https://web.archive.org/web/20140906020658/https://developers.google.com/webmasters/richsnippets/sitelinkssearch) Google Developers via the Wayback Machine
- [Sitelinks search box (2015 snapshot)](https://web.archive.org/web/20150316142805/https://developers.google.com/structured-data/slsb-overview) Google Developers via the Wayback Machine
- [Farewell, Sitelinks Search Box](https://developers.google.com/search/blog/2024/10/sitelinks-search-box) Google Search Central Blog
- [Site names in Google Search](https://developers.google.com/search/docs/appearance/site-names) Google Search Central
- [Schema Markup Validator](https://validator.schema.org/) Schema.org
- [Yoast: SearchAction](https://developer.yoast.com/features/schema/pieces/searchaction/) Yoast
- [Rank Math: sitelinks search box schema](https://rankmath.com/kb/sitelinks-searchbox-schema/) Rank Math
- [AIOSEO: sitelinks search box](https://aioseo.com/docs/how-to-get-google-to-display-the-sitelinks-search-box/) All in One SEO
