Skip to content

Fix: Meta Description: Issue with Yoast plugin for Meta Description experiment - #886

Merged
dkotter merged 1 commit into
WordPress:developfrom
hbhalodia:fix/issue-874
Jul 20, 2026
Merged

Fix: Meta Description: Issue with Yoast plugin for Meta Description experiment#886
dkotter merged 1 commit into
WordPress:developfrom
hbhalodia:fix/issue-874

Conversation

@hbhalodia

@hbhalodia hbhalodia commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #874

Why?

  • PR resolves the issue where, Yoast meta description is only saved for posts and no other post types.
  • It also resolves the issue where, Yoast AI is disable, still meta description is saved via yoast.
  • Read more on issue mentioned.

How?

  • Adds the seo-adapter.ts file, which register the adapter and use the required SEO adapters to work with.
  • If the Yoast plugin is active, the adapter uses Yoast method and way to store/fetch the meta description, else fallback to default what's being performed.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 4.8
Used for: Initial code implementation and final implementation and testing was done by me.

Testing Instructions

  1. Open both post and page.
  2. Make sure to activate yoast plugin.
  3. Use Meta Description experiment to generated meta description.
  4. See both post and page stores the meta description correctly to Yoast meta and our custom meta description box.

Screenshots or screencast

Screen.Recording.2026-07-20.at.1.21.22.PM.mov

Changelog Entry

Fixed - Meta Description suggestions applied on pages and custom post types were lost on save when Yoast SEO was active.


AI Summary

What?

Routes the Meta Description Apply action through the active SEO plugin's own editor store instead of always writing to core/editor post meta. Introduces a small, slug-keyed adapter layer and ships a Yoast adapter, so an applied AI meta description updates the SEO plugin UI and persists on all post types (posts, pages, and CPTs).

Why?

useMetaDescription.applyDescription wrote the suggestion via editPost( { meta: { [ metaKey ]: text } } ) (the core/editor store). That only works when the meta key is REST-registered for the current post type:

  • No SEO plugin: the plugin registers its fallback key for all REST post types, so this already works everywhere.
  • Yoast active: Yoast exposes _yoast_wpseo_metadesc to REST only for the post post type (register_meta( … 'object_subtype' => 'post' )). On a page or CPT the key isn't REST-registered, so editPost is dropped on save and the Yoast snippet field (bound to the yoast-seo/editor store) never reflects it — the applied description is lost. It also only appeared to work on posts when Yoast's own AI feature happened to be enabled, because that feature mounts the hook that mirrors core/editor meta into the Yoast store.

The fix targets the SEO plugin's own store, which is the source of truth for its UI and its all-post-type save path.

How?

  • New src/experiments/meta-description/seo-adapters.ts — a SeoEditorAdapter abstraction (apply / read) selected by the active plugin slug (window.aiMetaDescriptionData.seoPlugin):
    • defaultAdapter — unchanged behaviour: editPost on the meta key; reads from core/editor meta. Used for the fallback key and any not-yet-adapted SEO plugin.
    • yoastAdapterapply dispatches updateData( { description } ) to yoast-seo/editor (drives the UI + Yoast's metabox save on every post type) and calls editPost to mark the editor dirty so the Save button enables (and to persist via REST on post). read uses getSnippetEditorDescription() with a fallback to core meta if the Yoast store isn't ready.
    • getAdapter() with an ai.metaDescription.seoAdapters JS filter, mirroring the existing PHP wpai_meta_description_seo_plugins filter for extensibility.
  • components/useMetaDescription.ts — selects the adapter by slug, routes applyDescription through adapter.apply(), and derives currentDescription from adapter.read() (fixing the display / "already set" check on Yoast pages, where core/editor meta doesn't carry the key).
  • PHP unchangedSEO_Integration remains the single source of truth for detection and the meta key. Which plugin is active and its key stay server-side; how to write to the editor store is client-side, per-plugin behaviour.

Scope: ships the Yoast adapter only. Rank Math / All in One SEO / SEOPress continue to use the default (editPost) adapter until each is verified — dedicated adapters can be added incrementally (AIOSEO in particular uses a non-@wordpress/data store).

Testing Instructions

Preconditions: an AI connector with a text-generation model configured, and the Meta Description experiment enabled.

  1. Yoast active — Page (the bug): Activate Yoast SEO. Edit a Page with ≥250 characters of content. Open the Meta Description panel → GenerateApply.
    • The Yoast "Meta description" field/snippet preview updates to the applied text.
    • The Save/Update button becomes enabled even with no other edit.
    • Save → reload: the value persists; the front end outputs <meta name="description" …> with the text.
  2. Yoast active — Post: Repeat step 1 on a Post; confirm it still works.
  3. Yoast active — CPT: Repeat on a public custom post type that shows the Yoast metabox.
  4. Yoast AI feature on/off: Repeat step 1 with Yoast's own AI feature toggled both ways — behaviour should now be identical.
  5. No SEO plugin (regression): Deactivate all SEO plugins. Generate → Apply on a Post and a Page; confirm the value persists in the fallback meta and renders in the head (default path unchanged).
Open WordPress Playground Preview
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.44%. Comparing base (6dcd0ab) to head (bfba0be).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #886   +/-   ##
==========================================
  Coverage      78.44%   78.44%           
  Complexity      2454     2454           
==========================================
  Files            104      104           
  Lines           9925     9925           
==========================================
  Hits            7786     7786           
  Misses          2139     2139           
Flag Coverage Δ
unit 78.44% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@hbhalodia
hbhalodia marked this pull request as ready for review July 20, 2026 07:54
@hbhalodia
hbhalodia requested a review from a team July 20, 2026 07:54
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: hbhalodia <hbhalodia@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@dkotter dkotter added this to the 1.3.0 milestone Jul 20, 2026
@dkotter
dkotter merged commit b15cb96 into WordPress:develop Jul 20, 2026
26 of 27 checks passed
@dkotter

dkotter commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Note we'll want to credit @carlos-widgilabs on this as well, which wasn't captured by prop bot cc / @jeffpaul

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

Labels

None yet

2 participants