mupic/wp-api-yoast-meta

此包的最新版本(2.2.0)没有可用的许可证信息。

2.2.0 2019-04-17 18:12 UTC

This package is auto-updated.

Last update: 2024-09-18 06:28:17 UTC


README

支持 Yoast SEO >= 11.0

安装

composer require mupic/wp-api-yoast-meta

用于新WP REST API

返回 Yoast 文章或页面元数据,在常规文章或页面请求中。在返回数据的 yoast_meta 字段中存储元数据。

默认常量

//GET params will take precedence over constants
define('YOAST_REST_META', false); //false - Disable automatic meta seo input. (Equivalent in get request: meta=false)
define('YOAST_REST_OG', false); //false - Disable automatic open graph input. (Equivalent in get request: opengraph=false)
define('YOAST_REST_TW', false); //false - Disable automatic meta twitter input. (Equivalent in get request: twitter=false)
define('YOAST_REST_BC', false); //true - Return json breadcrumbs. "html" - Return html generated breadcrumbs. (Equivalent in get request: breadcrumbs=false)
define('YOAST_REST_SCHEMA', false); //false - Disable automatic microdata input. (Equivalent in get request: schema=false)

define('YOAST_REST_ENABLE_EMBED', false); //false - Disable yoast in fields called from _embed=true. (Equivalent in get request: yoast_embed=false)

示例

//wp-json/wp/v2/posts/123?yoast_meta=true&opengraph=true&twitter=true&breadcrumbs=true&schema=true
{
	id: 123,
	...
	yoast:{
		breadcrumbs: {
			links: [
				0: {
					allow_html: true
					text: "Home"
					url: "http://example.com/"
				},
				1: {
					text: "News"
					url: "http://example.com/category/news/"
				},
				2: {
					text: "Title"
					url: "http://example.com/news/title/"
				}
			],
			separator: "»"
		},
		meta: {
			canonical: "http://example.com/news/title/"
			description: "Description"
			article:modified_time: "2019-04-01T16:22:10+00:00"
			article:published_time: "2019-01-10T13:05:30+00:00"
			article:section: "News"
			article:tag: ["Tag1", "Tag2"]
			og:description: "Description"
			og:image: "http://example.com/wp-content/uploads/2019/01/6JHYYbvoSuQ95ceGx8Oeg8zzAjg-550x309.jpg"
			og:image:height: "309"
			og:image:width: "550"
			og:locale: "en_US"
			og:site_name: "Site"
			og:title: "Title - site"
			og:type: "article"
			og:updated_time: "2019-04-01T16:22:10+00:00"
			og:url: "http://example.com/news/title/"
			title: "Title - site"
			twitter:card: "summary"
			twitter:description: "Description"
			twitter:image: "http://example.com/wp-content/uploads/2019/01/6JHYYbvoSuQ95ceGx8Oeg8zzAjg.jpg"
			twitter:title: "Title - site"
		},
		schema: "{"@context":"https://schema.org","@graph":[...]}" //all schemes
	}
}
//yoast_api/v1/home?yoast_meta=true&opengraph=true&twitter=true&breadcrumbs=true&schema=true
{
	breadcrumbs: {
		links: [
			0: {
				allow_html: true
				text: "Home"
				url: "http://example.com/"
			}
		],
		separator: "»"
	},
	meta: {
		canonical: "http://example.com/"
		description: "Description"
		og:description: "Description"
		og:locale: "en_US"
		og:site_name: "Site"
		og:title: "Title - site"
		og:type: "website"
		og:url: "http://example.com/"
		title: "Title - site"
		twitter:card: "summary"
		twitter:description: "Description"
		twitter:title: "Title - site"
	},
	schema: {
		organization: "{"@context":"https://schema.org","@type":"Organization","url":"http://example.com/","sameAs":[],"@id":"http://example.com/#organization","name":"My super company","logo":"http://example.com/wp-content/uploads/2019/02/7e55b905c43b67479065761d49f0dcb8-2.png"}",
		website: "{"@context":"https://schema.org","@type":"WebSite","@id":"http://example.com/#website","url":"http://example.com/","name":"SiteName","potentialAction":{"@type":"SearchAction","target":"http://example.com/?s={search_term_string}","query-input":"required name=search_term_string"}}"
	}
}
//wp-json/wp/v2/posts/123?yoast_meta=true&breadcrumbs=html
{
	id: 123,
	...
	yoast:{
		breadcrumbs: {
			html: "<span><span><a href="http://example.com/" >Home</a> » <span><a href="http://example.com/category/news/" >News</a> » <span class="breadcrumb_last" aria-current="page">Title</span></span></span></span>"
		},
		meta: {...}
	}
}

支持页面、文章、任何 public 自定义文章类型、分类、标签、任何 show_in_rest 自定义分类法

当前正在获取

  • 规范链接
  • 描述
  • yoast_wpseo_title
  • yoast_wpseo_metadesc
  • yoast_wpseo_canonical
  • article:modified_time
  • article:published_time
  • article:section
  • article:tag
  • og:description
  • og:image
  • og:image:height
  • og:image:width
  • og:locale
  • og:site_name
  • og:title
  • og:type
  • og:updated_time
  • og:url
  • 标题
  • twitter:card
  • twitter:description
  • twitter:image
  • twitter:title

当前正在更新

  • yoast_wpseo_focuskw
  • yoast_wpseo_title
  • yoast_wpseo_metadesc
  • yoast_wpseo_linkdex
  • yoast_wpseo_metakeywords
  • yoast_wpseo_meta-robots-noindex
  • yoast_wpseo_meta-robots-nofollow
  • yoast_wpseo_meta-robots-adv
  • yoast_wpseo_canonical
  • yoast_wpseo_redirect
  • yoast_wpseo_opengraph-title
  • yoast_wpseo_opengraph-description
  • yoast_wpseo_opengraph-image
  • yoast_wpseo_twitter-title
  • yoast_wpseo_twitter-description
  • yoast_wpseo_twitter-image

https://github.com/ChazUK/wp-api-yoast-meta 分支而来