只要在每個網頁中加入幾行程式碼,就能調整網站透過社群媒體分享時的顯示方式。這樣一來,預覽畫面就能提供更豐富的資訊,吸引更多人造訪網站。
只要在每個網頁中加入幾行程式碼,就能調整網站透過社群媒體分享時的顯示方式。這有助於提供更豐富的預覽資訊,吸引更多使用者造訪網站。
摘要
- 使用 schema.org 微資料,為 Google+ 提供網頁標題、說明和圖片。
- 使用 Open Graph 通訊協定 (OGP) 提供 Facebook 網頁標題、說明和圖片。
- 使用 Twitter 卡片,為 Twitter 提供網頁標題、說明、圖片和 Twitter ID。
只要在每個網頁中加入幾行程式碼,就能調整網站透過社群媒體分享時的顯示方式。這有助於提供比其他方式更豐富的預覽資訊,進而提高參與度。如果沒有這項資訊,社群網站只會提供基本資訊,不會顯示圖片或其他實用資訊。
你認為哪一個比較可能獲得點擊?圖片能吸引使用者,讓他們在預覽後更有信心,相信自己會喜歡找到的內容。
當社群網路上的使用者想與朋友分享你的網站時,可能會加上一些說明,解釋網站有多棒,然後分享。但描述網站往往很繁瑣,而且可能無法切中網頁擁有者的觀點。部分服務會限制使用者在附註中輸入的字元數。
只要在網頁中加入適當的中繼資料,就能提供標題、說明和吸引人的圖片,簡化使用者的分享程序。這表示他們不必花費寶貴的時間 (或字元) 描述連結。
使用 schema.org + 微資料在 Google+ 上提供複合式摘要
檢索器會使用多種方法剖析網頁並瞭解內容。使用微資料和 schema.org 詞彙,可協助社群網站和搜尋引擎進一步瞭解網頁內容。
範例如下:
<div itemscope itemtype="http://schema.org/Article">
<h1 itemprop="name">Enjoy fireworks</h1>
<p itemprop="description">Fireworks are beautiful.
This article explains how beautiful fireworks are.</p>
<img itemprop="image" src="//developers.google.com/web/imgs/fireworks.jpg" />
</div>
雖然大多數中繼資料都嵌入在網頁的 head 區段中,但微資料會出現在內容所在的位置。
新增 itemscope 定義微資料範圍
加入 itemscope 後,您就能將標記指定為特定項目的內容區塊。
新增 itemtype 來定義網站類型
您可以使用 itemtype 屬性搭配 itemscope 指定項目類型。itemtype 的值可根據網頁上的內容類型決定。您應該可以在這個頁面找到相關資訊。
新增 itemprop,使用 schema.org 詞彙描述每個項目
itemprop 會定義範圍內 itemtype 的屬性。如要向社群網站提供中繼資料,itemprop 的一般值為 name、description 和 image。
驗證複合式摘要
如要驗證 Google+ 上的複合式摘要,可以使用下列工具:
- 結構化資料測試工具 - Search Console
使用 Open Graph 通訊協定 (OGP) 在 Facebook 上提供複合式摘要
Open Graph 通訊協定 (OGP) 會向 Facebook 提供必要的中繼資料,讓網頁能與其他 Facebook 物件一樣運作。
<html prefix="og: http://ogp.me/ns#">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.2.1/material.min.js"></script>
<style>
body {
margin: 2em;
}
</style>
<meta property="og:title" content="Enjoy Fireworks">
<meta property="og:description"
content="Fireworks are beautiful. This article explains how beautiful fireworks are.">
<meta property="og:image"
content="https://developers.google.com/web/imgs/fireworks.jpg">
<meta property="og:url"
content="https://example.com/discovery-and-distribution/optimizations-for-crawlers/social-sites.html">
<meta property="og:type" content="website">
如果將這項中繼資料加入網頁的 head 區段,系統就會在分享網頁時提供複合式摘要資訊。
使用 og: 命名空間 meta 標記描述中繼資料
meta 標記包含 property 屬性和 content 屬性。屬性和內容可能包含下列值:
| 屬性 | 內容 |
|---|---|
og:title |
網頁標題。 |
og:description |
網頁說明。 |
og:url |
網頁的標準網址。 |
og:image |
分享貼文所附圖片的網址。 |
og:type |
表示網頁類型的字串。您可以在這裡找到適合網頁的標記。 |
這些中繼標記會向 Facebook 等社群網站的檢索器提供語意資訊。
瞭解詳情
如要進一步瞭解可附加至 Facebook 貼文的內容,請造訪官方 Open Graph Protocol 網站。
驗證複合式摘要
如要驗證 Facebook 上的標記,可以使用下列工具:
使用 Twitter Cards 在 Twitter 上提供複合式摘要
Twitter Cards 是 Open Graph 通訊協定的延伸,適用於 Twitter。您可以在推文中加入圖片和影片等媒體附件,並附上網頁連結。只要加入適當的中繼資料,含有網頁連結的推文就會加入資訊卡,其中包含您新增的豐富詳細資料。
使用 twitter: 命名空間中繼標記描述中繼資料
如要讓 Twitter 卡片正常運作,網域必須獲得核准,且必須包含中繼標記,其中 twitter:card 為 name 屬性,而非 property 屬性。
請看以下的簡單範例:
<html prefix="og: http://ogp.me/ns#">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.2.1/material.min.js"></script>
<style>
body {
margin: 2em;
}
</style>
<meta property="og:title" content="Enjoy Fireworks">
<meta property="og:description"
content="Fireworks are beautiful. This article explains how beautiful fireworks are.">
<meta property="og:image"
content="https://developers.google.com/web/imgs/fireworks.jpg">
<meta property="og:url"
content="https://example.com/discovery-and-distribution/optimizations-for-crawlers/social-sites.html">
<meta property="og:type" content="website">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="agektmr">
將 Twitter ID 指派給 twitter:site 的值後,Twitter 會將這項資訊嵌入分享的貼文中,方便使用者與網頁擁有者互動。
瞭解詳情
如要進一步瞭解 Twitter 卡片,請前往:
驗證複合式摘要
Twitter 提供以下工具,可用來驗證標記:
最佳做法
綜合以上三種做法,最好的方式是在網頁中同時採用這三種做法。範例如下:
<!-- namespace declaration -->
<html prefix="og: http://ogp.me/ns#">
<!-- define microdata scope and type -->
<head itemscope itemtype="http://schema.org/Article">
<title>Social Site Example</title>
<!-- define ogp and itemprop of microdata in one line -->
<meta property="og:title" itemprop="name" content="Enjoy Fireworks">
<!-- define ogp image -->
<meta property="og:image"
content="https://developers.google.com/web/imgs/fireworks.jpg">
<!-- use link[href] to define image url for microdata -->
<link itemprop="image" href="//developers.google.com/web/imgs/fireworks.jpg">
<!-- define ogp and itemprop of microdata in one line -->
<meta property="og:url"
content="https://example.com/discovery-and-distribution/optimizations-for-crawlers/social-sites2.html">
<!-- define ogp type -->
<meta property="og:type" content="website">
<!-- define twitter cards type -->
<meta name="twitter:card" content="summary_large_image">
<!-- define site's owner twitter id -->
<meta name="twitter:site" content="agektmr">
<!-- define description for ogp and itemprop of microdata in one line -->
<meta property="og:description" itemprop="description"
content="Fireworks are beautiful. This article explains how beautiful fireworks are.">
<!-- general description (separate with ogp and microdata) -->
<meta name="description"
content="Fireworks are beautiful. This article explains how beautiful fireworks are.">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.2.1/material.min.js"></script>
<style>
body {
margin: 2em;
}
</style>
</head>
請注意,微資料和 OGP 共用部分標記:
itemscope位於head標記title和description會在微資料和 OGP 之間共用itemprop="image"使用的是link標記和href屬性,而不是重複使用meta標記和property="og:image"
最後,請務必先確認網頁在各個社群網站上都能正常顯示,再發布網頁。