Skip to content

Fuxt API - Yoast SEO Field#116

Open
dChiamp wants to merge 1 commit into
mainfrom
yoast-seo
Open

Fuxt API - Yoast SEO Field#116
dChiamp wants to merge 1 commit into
mainfrom
yoast-seo

Conversation

@dChiamp

@dChiamp dChiamp commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What

Adds an optional seo value to the fields param on the /fuxt/v1/post and /fuxt/v1/posts endpoints. When requested (e.g. ?uri=/home/&fields=acf,seo), the response includes the full Yoast SEO meta payload for the post — title, description, robots, canonical, all Open Graph and Twitter tags, article timestamps, and the complete JSON-LD schema graph.

Why

Our fuxt endpoints build responses with custom callbacks rather than WP core REST controllers, so Yoast's automatic yoast_head_json field never appears on them. This exposes the same data through the existing fields pattern, letting headless frontends render full SEO head tags from the single page fetch they already make.

How

  • Post::get_postdata() gains a seo block that calls Yoast's surface API: YoastSEO()->meta->for_post( $id )->get_head()->json
  • Guarded by function_exists( 'YoastSEO' ) — returns seo: null when Yoast isn't active, so this is safe on sites without the plugin
  • seo is not inherited by children/siblings/next/prev sub-posts, to keep list responses lean
  • Registered in the fields enum, allowed-fields list, and item schema on both controllers

Two payload adjustments for headless clients that camelCase response keys:

  • schema is shipped as a JSON string (not an object) so JSON-LD keys like @context/@graph survive client-side key transforms — inject it directly into a <script type="application/ld+json"> tag
  • twitter_misc is dropped (keyed by human-readable labels, which key transforms would mangle)

Frontend reference

The corresponding Nuxt consumption pattern lives on the freshman-year frontend's yoast-seo branch: a prop-driven wp-seo.vue that maps the camelCased seo object to useSeoMeta/useHead (with site-settings fallbacks), pages adding seo to their fields param, and a titleTemplate guard since Yoast titles already include the site name. Use that as the template when rolling this out to other fuxt sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant