mupic / wp-api-yoast-meta
Installs: 29
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 67
pkg:composer/mupic/wp-api-yoast-meta
README
Supports Yoast SEO >= 11.0
Install
composer require mupic/wp-api-yoast-meta
For use with the new WP REST API
Returns Yoast post or page metadata in a normal post or page request. Stores the metadata in the yoast_meta field of the returned data.
Default constants
//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)
Examples
//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: {...}
	}
}
Supports pages, posts, any public custom post types, categories, tags, any show_in_rest custom taxonomies
Currently fetching:
canonicaldescriptionyoast_wpseo_titleyoast_wpseo_metadescyoast_wpseo_canonicalarticle:modified_timearticle:published_timearticle:sectionarticle:tagog:descriptionog:imageog:image:heightog:image:widthog:localeog:site_nameog:titleog:typeog:updated_timeog:urltitletwitter:cardtwitter:descriptiontwitter:imagetwitter:title
Currently updating:
yoast_wpseo_focuskwyoast_wpseo_titleyoast_wpseo_metadescyoast_wpseo_linkdexyoast_wpseo_metakeywordsyoast_wpseo_meta-robots-noindexyoast_wpseo_meta-robots-nofollowyoast_wpseo_meta-robots-advyoast_wpseo_canonicalyoast_wpseo_redirectyoast_wpseo_opengraph-titleyoast_wpseo_opengraph-descriptionyoast_wpseo_opengraph-imageyoast_wpseo_twitter-titleyoast_wpseo_twitter-descriptionyoast_wpseo_twitter-image