Expand the Yoast title templates in seo_title - #225
Merged
Conversation
WordPress stored an article's SEO title as a Yoast template rather than as finished text -- "%%title%% %%page%%", or a headline with "%%page%% %%sep%% %%sitename%%" appended -- and Yoast substituted the variables when it rendered the page. BackfillArticleSEOFromYoast copies that value into seo_title verbatim, and nothing substitutes it now, so the tokens reach the public site's <title>, og:title and twitter:title as themselves: a 2022 crossword is "%%title%% %%page%%" in the browser tab, in search results and on every shared link. 79 of 10,190 articles in production hold one, all imported from the 2022-2023 Yoast era. Expand them, mirroring expandSeoVariables in Scalene's seoTemplate.ts so the CMS and the public site agree on what a template means. %%page%% expands to nothing, as it did under Yoast -- it numbers a paginated archive, and an article is one page -- and an unrecognised variable is dropped rather than printed. A template that says no more than the headline, which is what Yoast's default meant, is stored blank: the site renders the headline for a blank seo_title, the SEO audit already treats that as correct, and it keeps tracking the headline if an editor rewrites it. The pass runs on every start rather than behind the backfill's one-time flag, because the databases that already hold these templates were seeded before this existed and the backfill only ever fills blanks. It is idempotent: expanded text carries no variables, so a second pass matches nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tx3ywgRQLzzrZWNcSdtTpr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the
%%title%% %%page%%browser tab on/article/with-you-rugby-crossword. Scalene PR #102 stops the tokens rendering; this fixes the data they come from.WordPress stored SEO titles as Yoast templates, and
BackfillArticleSEOFromYoastcopies them intoseo_titleverbatim. 79 of 10,190 production articles hold one, all from the 2022–2023 Yoast era, all inseo_title(meta_description,excerpt,title,focus_keywordandcanonical_urlare clean — checked).What it does
ExpandYoastTitlemirrorsexpandSeoVariablesin Scalene'ssrc/utils/seoTemplate.ts, so the CMS and the public site agree on what a template means:%%title%%,%%sitename%%,%%primary_category%%,%%sep%%are substituted;%%page%%expands to nothing, as it did under Yoast (it numbers a paginated archive, and an article is one page); anything unrecognised is dropped rather than printed.%%title%% %%page%%) is stored blank, not expanded: the site renders the headline for a blankseo_title,auditArticlealready treats blank as correct, and it keeps tracking the headline if an editor rewrites it later. 49 of the 79 land here; 30 carry real editor-written titles and keep them.The pass runs on every start rather than behind the backfill's one-time flag — the databases holding these templates were seeded before this existed, and the backfill only fills blanks. Idempotent: expanded text has no variables, so a second pass matches nothing.
Testing
yoast_title_test.go), plus idempotency and the redundant-title rule.go build ./...andgo test ./internal/database/pass.Deploying this performs the backfill
On the next deploy the startup pass rewrites those 79 rows. Two of them are worth an editor's eye afterwards — their stored templates are malformed, with a note appended after
%%sitename%%, and expand faithfully but awkwardly:8835the-triangles-guide-to-running-in-philadelphia →The Triangle's guide to running in Philadelphia - The Triangle How to run in Philly8836sixers-win-play-in-game-clinch-no-7-seed →Sixers win play-in game, clinch No. 7 seed - The Triangle Sixers win play-in gameBoth are editable in the CMS SEO panel; I did not guess at what they were meant to say.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Tx3ywgRQLzzrZWNcSdtTpr