[WordPress] 外掛分享: Open Graph Protocol Framework

首頁外掛目錄 › Open Graph Protocol Framework
WordPress 外掛 Open Graph Protocol Framework 的封面圖片
3,000+
安裝啟用
★★★★
4.3/5 分(15 則評價)
88 天前
最後更新
問題解決
WordPress 6.0+ PHP 7.4+ v2.1.0 上架:2012-12-20

內容簡介

開放圖形協定(Open Graph protocol)可讓任何網頁成為社交圖形中的豐富物件。例如,Facebook 上就使用這個協定,讓任何網頁都可以具有 Facebook 上的任何其他物件的功能。

本WordPress外掛旨在自動化添加基本和可選元數據到站點的頁面的過程。它還被設計為其他外掛或主題的框架,允許根據需要修改和適應提供的信息。

如果您發現此外掛有用,並想支持我們的工作,可以在商店購買,謝謝!

用法

安裝並啟用外掛。它會自動為文章、頁面等呈現以下元數據:

og:title:使用頁面的標題,這為文章、頁面、存檔等提供了標題。
og:type:通常為article,首頁為website,博客主頁為blog。
og:image:對於支持特色圖像的文章類型,使用特色圖像的 URL。其他元數據包括og:image:width、og:image:height、og:image:url、og:image:secure_url 和og:image:alt。
og:url:當前頁面的 URL。
og:site_name:站點名稱。
og:description:如果可用則使用完整摘要,否則從內容中進行推導。對於作者和存檔頁面,使用頁面類型和標題。
og:locale:當前區域設置。
og:locale:alternate:如果安裝了WPML,則表明可用的其他區域設置。

og:image:alt屬性的內容基於特色圖像的替代文字、缺少替代文字時的圖像標題,或缺少這些的圖像說明。如果這些任何一個為空,則不呈現此屬性。

過濾器

此部分是為開發人員而寫的。如果您不是開發人員,可以安全地跳過它。

外掛提供以下過濾器:

open_graph_protocol_meta

此過濾器允許修改給定元標記的content屬性的值。
它被用於支持的每種元數據。

參數:

string content - 當前的content屬性值
string property - 元數據名稱,例如og:title

過濾器必須返回:

string -content屬性的所需值

open_graph_protocol_meta_tag

此過濾器允許修改實際呈現在頁面<head>中的HTML<meta>標記。

參數:

string - HTML <meta>標記。
string property - 元數據名稱,例如og:title
string content - content 屬性的值

過濾器必須返回:
- string HTML<meta>標記的所需輸出。

open_graph_protocol_metas

此過濾器允許在呈現元數據之前添加或刪除元數據。

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Open Graph Protocol Framework」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.
This WordPress plugin is aimed at automating the process of adding basic and optional metadata to a site’s pages. It is also designed to act as a framework for other plugins or themes and allows to modify and adapt the information provided as needed.
If you find this plugin useful and would like to support our work, you can do so by purchasing in our Shop, thank you!
Supports WooCommerce to include essential product metadata on product pages.
Usage
Install and activate the plugin. It will automatically render the following metadata for posts, pages, etc. :

og:title : The page’s title is used, this provides the title for posts, pages, archives etc.
og:type : The type will be article in general, website for the front page and blog for the blog homepage.
og:image : For post types that support featured images, the URL of the featured image is used. Additional metadata og:image:width, og:image:height, og:image:url, og:image:secure_url and og:image:alt are added.
og:url : The URL of the current page.
og:site_name : The name of the site.
og:description : Uses the full excerpt if available, otherwise derives it from the content. For author and archive pages, the type of page and title is used.
og:locale : The current locale.
og:locale:alternate : Indicates additional locales available with WPML and Polylang.

The content of the og:image:alt property is based on the Alt Text of the featured image, the image’s Caption in lack thereof, or ultimately the image’s Description in lack of the latter. If any of those are empty, the property is not rendered.
Filters
This section is for developers. If you’re not a developer, you can safely skip it.
The plugin provides the following filters:
open_graph_protocol_meta
This filter allows to modify the value of the content attribute for a given meta tag.
It is invoked for every supported type of metadata.
Parameters:

string content – the current value of the content attribute
string property – the metadata name, for example og:title

Filters must return:

string the desired value of the content attribute

open_graph_protocol_meta_tag
This filter allows to modify the actual HTML tag that is rendered in the section of pages.
Parameters:

string HTML tag
string property – the metadata name, for example og:title
string content – the value of the content attribute

Filters must return:

string the desired output for the HTML tag

open_graph_protocol_metas
This filter allows to add or remove metadata before it is rendered.
Parameters:

array of metadata indexed by metadata name

Filters must return:

array of metadata indexed by metadata name

open_graph_protocol_echo_metas
This filter allows to modify the HTML that renders the plugin’s meta tags in the section.
Parameters:

string HTML with tags to be rendered

Filters must return:

string HTML with tags to be rendered

open_graph_protocol_framework_ext
This filter allows to determine whether additional meta tags should be produced for supported integrations.
Parameters:

boolean whether to process the integration
string the integration

Filters must return:

boolean whether to process additional meta tags for the integration

Why this plugin?
This plugin was created because we needed an extendable way to render meta tags based on the Open Graph protocol, which would allow to modify the meta tag content rendered or add meta tags when appropriate based on external data.
None of the existing plugins provided a sufficiently flexible way of doing that, among other reasons we needed a solution that would comply with all of these requirements and none of the existing solutions does:

must be compatible with WordPress 3.5
must automatically add meta tags for featured images
must be automated and create sensible meta tag content for each page, we don’t want to manually indicate the tag content for every page
must provide a framework for extension through hooks and filters on every tag, and provide a design that allows other plugins to modify the meta tags in flexible ways
must not ask to provide your Facebook account details or application ID when there is no need for it
must not be bloated with features you don’t want or need when you simply want Open Graph metatags to be rendered automatically for your pages

Logo Attribution
The logo used for this plugin’s icon and banner is the Open Graph protocol logo by Facebook – ogp.me. Licensed under Public Domain via Wikimedia Commons.
Validators
To test the generated metadata you can use several tools, among those:

X Card Validator
Meta Sharing Debugger

延伸相關外掛

文章
Filter
Apply Filters
Mastodon