You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何自动在Sitelinks Searchbox加网址?多子域名批量实现问询

Hey there, let's break down your two questions one by one—super common stuff when optimizing for Google Search, so I've got you covered:

Sitelinks Searchbox lets users search directly your site from Google's search results, and while Google decides whether to show it, you can drastically boost your chances with structured data. Here's how to set it up automatically:

  • First, cover the basics: Make sure your site is verified in Google Search Console (GSC) and Google has indexed your core pages. Without these, the search box won't show up no matter what.
  • Add SearchAction structured data (JSON-LD preferred)
    Google recommends JSON-LD for structured data because it's easy to implement and maintain. Drop this code in the <head> section of your pages (at minimum, your homepage—this is where the search box is most likely to appear):
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "WebSite",
      "url": "https://www.mywebsite.com/",
      "potentialAction": {
        "@type": "SearchAction",
        "target": "https://www.mywebsite.com/search?q={search_term_string}",
        "query-input": "required name=search_term_string"
      }
    }
    </script>
    
    • Replace https://www.mywebsite.com/ with your actual site URL.
    • The target value should point to your internal search results page, where {search_term_string} acts as a placeholder for the user's query (Google handles replacing this).
  • Critical checks:
    • Ensure your internal search works properly and returns relevant results—Google tests this, so a broken or low-quality search tool will kill your chances.
    • Don't duplicate this structured data across pages; each page only needs one WebSite entry.
    • Be patient! Google needs to re-crawl your site to pick up the changes, which can take a few days to a couple of weeks.
2. 多子域名自动添加网站链接(结构化数据)

Absolutely! The key is using dynamic code or template systems to generate the correct structured data for each subdomain, so you don't have to manually copy-paste across it.mywebsite.com, es.mywebsite.com, etc. Here are common implementations based on your tech stack:

Server-side languages (PHP, Python, etc.)

If your sites are built with server-side code, use dynamic variables to pull the current domain. For example, in PHP:

<?php
// Dynamically get the current domain and protocol
$currentProtocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http";
$currentDomain = $_SERVER['HTTP_HOST'];
$currentUrl = "$currentProtocol://$currentDomain/";
$searchUrl = "$currentUrl/search?q={search_term_string}";
?>
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "url": "<?php echo htmlspecialchars($currentUrl); ?>",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "<?php echo htmlspecialchars($searchUrl); ?>",
    "query-input": "required name=search_term_string"
  }
}
</script>

Drop this in your global header template, and every subdomain will automatically get the correct structured data without manual edits.

Static site generators (Next.js, Gatsby, Eleventy)

For static sites, use your generator's layout component to inject dynamic data. Here's an example with Next.js:

import { useRouter } from 'next/router';

function MyApp({ Component, pageProps }) {
  const router = useRouter();
  // Get the current domain from the window object (client-side)
  const currentDomain = typeof window !== 'undefined' ? window.location.host : '';
  const currentUrl = `https://${currentDomain}/`;
  const searchUrl = `${currentUrl}search?q={search_term_string}`;

  return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{
          __html: JSON.stringify({
            "@context": "https://schema.org",
            "@type": "WebSite",
            "url": currentUrl,
            "potentialAction": {
              "@type": "SearchAction",
              "target": searchUrl,
              "query-input": "required name=search_term_string"
            }
          })
        }}
      />
      <Component {...pageProps} />
    </>
  );
}

export default MyApp;

This will automatically generate the right structured data for every subdomain when your site builds.

CMS platforms (WordPress, Shopify)

  • WordPress: Use the global home_url() function in your theme's header.php file:

    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "WebSite",
      "url": "<?php echo esc_url(home_url('/')); ?>",
      "potentialAction": {
        "@type": "SearchAction",
        "target": "<?php echo esc_url(home_url('/search/?q={search_term_string}')); ?>",
        "query-input": "required name=search_term_string"
      }
    }
    </script>
    

    For WordPress multisite setups, this will automatically adapt to each subdomain's URL.

  • Shopify: Edit your theme.liquid file and use Shopify's {{ shop.url }} variable:

    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "WebSite",
      "url": "{{ shop.url }}",
      "potentialAction": {
        "@type": "SearchAction",
        "target": "{{ shop.url }}/search?q={search_term_string}",
        "query-input": "required name=search_term_string"
      }
    }
    </script>
    

Final note: Don't forget to verify each subdomain in Google Search Console separately—this helps Google associate the structured data with the correct domain.

内容的提问来源于stack exchange,提问作者user9355587

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:59:23