[WordPress] 外掛分享: REST API – Head Tags

WordPress 外掛 REST API – Head Tags 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「REST API – Head Tags」是 2020-01-12 上架。
  • 目前有 200 個安裝啟用數。
  • 上一次更新是 2021-03-26,距離現在已有 1501 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.7 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 5.6 以上。
  • 有 2 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

poliuk | orballo | frontity | davidarenas | luisherranz | rmartinezduque | santosguillamot |

外掛標籤

api | seo | meta | rest | Yoast |

內容簡介

此外掛程式將整個 head 區段的標籤添加至 WordPress REST API 回應中。

如果您使用 WordPress 進行 headless 設置並希望添加由 WordPress SEO 外掛(例如 Yoast SEO 或 All-in-One SEO Pack)產生的 meta 標籤至 WordPress REST API 輸出,那麼此外掛程式非常適合您。

需求

這個套件需要 PHP DOM 庫 的相依性。大部分的 PHP 環境都會預設安裝,所以您不需要擔心這個問題。

如果您遇到相關的相依性錯誤,請確認您是否已安裝此庫(您可以參考這個程式庫中的討論串)。

相容性

此外掛程式與其中一些最受歡迎的 WordPress SEO 外掛相容且開箱即用。以下是我們測試過的外掛程式:

Yoast SEO – (版本至 13.5)
All in One SEO Pack – (版本至 3.4.2)
WP SEO –

如果您使用的是不同的 SEO 外掛並想知道它是否相容,歡迎到我們的社群論壇提問。如果您有測試過其他外掛程式,也請告知我們以便更新列表。

如何使用此外掛程式
含有 head 標籤的項目

此外掛程式已開發成為將 head_tags 欄位包含至大部分 WordPress 核心項目的 REST API 回應中:

文章、頁面、附件及自訂文章類型。
文章類型:用於存檔頁面。
類別、標籤及自訂稅項。
作者。

在 Frontity 專案中

如果您使用 Frontity,只需安裝 @frontity/head-tags 套件,它就會自動運作。

在其他專案中

您需要更深入理解其運作方式並手動添加資料。

如何手動取得 head_tags 欄位

您必須從各自的 REST API 終端點取得每個項目。例如:取得文章時,您應該前往 /wp-json/wp/v2/posts&id=123 終端點;取得類別時,您必須前往 wp-json/wp/v2/categories&id=123,而針對自訂文章類型或自訂稅項,每個案例的 URL 都不同。

對於首頁,它沒有非常直觀的 URL,您應該前往 /wp-json/wp/v2/types/post。如前所述,每個項目都有不同的終端點,因此如果您對此不熟悉,請查看WordPress REST API 參考文件以取得更多資訊。

在每個終端點內,會有一個名為 head_tags 的新欄位,它將是一個物件陣列,表示 WordPress 通常會包含在 HTML head 元素內的標籤。這些物件具有 tag、attributes 和 content 屬性。

例如,對於這些 HTML 標籤:

原文外掛簡介

This plugin adds all the tags in the head section of a website to WordPress REST API responses.
It is perfect if you are using WordPress for a headless set-up and would like to add the meta tags generated by your WordPress SEO plugin (like Yoast SEO or All-in-One SEO Pack) to the WordPress REST API output.
Requirements
This package depends on the PHP DOM library. Most PHP environments have it by default so you don’t have to worry about that.

In case you get some errors regarding this dependency make sure you have this library installed (you can take a look at this thread in the code repository).

Compatibility
This plugin is compatible and works out of the box with some of the most popular WordPress SEO plugins. These are the ones that we tested:

Yoast SEO – (up to 13.5)
All in One SEO Pack – (up to 3.4.2)
WP SEO –

Are you using a different SEO plugin and want to know if it’s compatible? Feel free to ask in our community forum. If you tested any other plugin, please let us know as well so we can update the list.
How to use this plugin
Entities with head tags
The plugin has been developed to include the head_tags field to the REST API response of most of the WordPress core entities:

Posts, pages, attachments and custom post types.
Post types: for archive pages.
Categories, tags and custom taxonomies.
Authors.

In a Frontity project
If you are using Frontity, you just have to install the @frontity/head-tags package and it will work automatically.
 In a different project
You need to understand better how it works and add the data manually.
How to fetch the head_tags field manually
You have to get each entity from its respective REST API endpoint. For example: for fetching the posts, you should go to /wp-json/wp/v2/posts&id=123 endpoint; for fetching the categories, you have to go to wp-json/wp/v2/categories&id=123, and for custom post types or custom taxonomies, it would be a different url in each case.
In the case of the homepage, it’s less intuitive and you should go to /wp-json/wp/v2/types/post. As previously said, each entity has a different endpoint so if you aren’t familiar with this, you should check out the WordPress REST API reference for more information.
Inside each endpoint, it will be a new field named head_tags, which will be an array of objects representing the tags that WordPress would normally include inside the html head element. These objects have the properties tag, attributes and content.
For example for these HTML tags:

Hello wordl! - My Site

This would be the content of the head_tags field:
"head_tags": [
{
"tag": "title",
"content": "Hello world! - My Site"
},
{
"tag": "meta",
"attributes": {
"name": "robots",
"content": "max-snippet:-1, max-image-preview:large, max-video-preview:-1"
}
},
{
"tag": "link",
"attributes": {
"rel": "canonical",
"href": ""
}
}
]

Settings
The settings of this plugin are really simple.
Purge cache
In order to not affect the performance of your site, the head_tags field is cached for all your responses. Each time you update a post/page/cpt or a taxonomy, the cache for that entity will be purged automatically. In case you make global changes (i.e. your permalinks or your global Yoast settings) use the Purge button to clean the whole cache.
 Enable output
By default, the head_tags field is included in the common endpoint of each entity. You can configure it so it doesn’t appear by default and to be shown when you include the head_tags=true query.
For example, with the output disabled, https://test.frontity.org/wp-json/wp/v2/posts won’t show the head_tags field unless you have the query ?head_tags=true at the end.
Skip cache
In case you want to skip the cache, you can do so by adding to the query the parameter skip_cache.
There are some cache plugins for the REST API which also use the same parameter. In case you want to ignore the cache for the REST API call but not for the head tags, you can use skip_cache&head_tags_skip_cache=false.
Problems and Questions
If you have any trouble with the REST API – Head Tags, you can check out our docs or join our community forum and let us know. We’ll be happy to help!
Bug reports for REST API – Head Tags plugin are welcomed in our repository on GitHub. Before opening an issue, please be sure to review the contributing guidelines.
More Information

About Frontity Framework
Guide on SEO for Headless WordPress Themes
Follow Frontity on Twitter and GitHub
Get help on the Frontity Community Forum

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「REST API – Head Tags」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0.0 | 1.0.1 | 1.1.0 | 1.1.1 | 1.1.2 | 1.1.3 | 1.1.4 | 1.2.0 | 1.2.1 |

延伸相關外掛(你可能也想知道)

  • Disable REST API 》這是最全面的 WordPress REST API 存取控制外掛!, 輕鬆安裝,安裝後不需要額外設定即可使用。只需上傳並啟用,整個 REST API 將無法被一般訪客存取。, 但如...。
  • Make Connector 》Make 是一個視覺化平台,讓你可以在幾分鐘內設計、建立和自動化任何事情 - 從簡單的任務到複雜的工作流程。使用 Make,你可以在 WordPress 和數千個應用程式...。
  • ACF to REST API 》此 WordPress 外掛在WordPress REST API中提供了Advanced Custom Fields的端點, 詳細資訊請參閱GitHub:https://github.com/airesvsg/acf-to-rest-api/。
  • Disable WP REST API 》這個外掛只有一個功能:禁用沒有登入 WordPress 的訪客使用 WP REST API。不需要任何設定。, 這個外掛只有 22 行短小的程式碼(少於 2KB)。因此它非常輕量、...。
  • WPGet API – Connect to any external REST API 》簡單地連接WordPress至外部API的最簡單方式。, , WPGetAPI 可輕鬆地從無限量的第三方 REST API 發送和接收資料,然後使用「Shortcode」或「Template Tag」格...。
  • WP REST Cache 》如果您在使用 WordPress REST API 時遇到速度問題,這個外掛將允許 WordPress 快取 REST API 的回應,使其更快。, 此外掛提供以下功能:, , 快取所有預設的 W...。
  • WP REST API Controller 》WP REST API Controller 外掛提供使用者易用的圖形化介面,使管理員可以切換 WordPress 核心和自訂文章類型以及分類法的可見性和端點,同時也可以自訂 API 回...。
  • Transbank Webpay REST 》透過 Webpay Plus 和 Webpay Oneclick 在你的 WooCommerce 上使用信用卡、借記卡和預付卡進行在線付款。
  • WordPress REST API (Version 2) 》WordPress 正轉變成一個完整的應用程式框架,因此需要新的 API。這個專案的目的是創建一個易於使用、易於理解且經過良好測試的框架,用於創建這些 API,以及...。
  • WP REST API – OAuth 1.0a Server 》使用這個外掛,您可以將應用程式連接至您的 WordPress 網站,而不必透露您的密碼。, 此外掛使用 OAuth 1.0a 協議,允許委派授權,即允許應用程式使用一組次要...。
  • REST API Meta Support 》此外掛可以自動將 WordPress REST API 的文章(/wp-json/wp/v2/posts)或頁面(/wp-json/wp/v2/pages) POST 中的 meta 欄位所包含的元數據自動存儲於建立的...。
  • Better REST API Featured Images 》注意:您可能不需要此外掛。 REST API 已經支援在 URL 中添加查詢參數 ?_embed,並且回應將包括所有“嵌入式媒體”,包括特色圖片,在那裡獲得的數據正是此外掛...。
  • REST API Toolbox 》此外掛允許調整多個 REST API 設定, , 停用 REST API, 移除 WordPress 核心端點, 需要核心端點驗證, 強制使用 SSL, WP-CLI 命令: wp rest-api-toolbox, , 在 ...。
  • Disable Gutenberg Autosave 》啟用此外掛後,Gutenberg 編輯器的自動儲存功能將被停用。您也可以在編輯器中選擇不同的自動儲存間隔時間(預設為 60 秒)。, 區塊編輯器仍會使用本地自動儲...。
  • WP-CORS 》來自其他網站的 AJAX 請求(其中包含 Origin 標頭)將被允許,並且會允許在外掛程式的「設定」頁面中列出的任何網域。。

文章
Filter
Mastodon