Skip to content

CPT excerpt migration for Yoast SEO

Last updated on June 8, 2026

A major cleanup pass was completed for excerpt generation across custom post types (CPTs), with the goal of improving search result snippets and making Yoast SEO descriptions more consistent without requiring manual meta entry for every piece of content.

The site already stores normalized plain‑text versions of content in custom fields such as quote_plain_text, lyric_plain_text, excerpt_plain_text, and definition. Since Yoast can automatically use the WordPress excerpt field as the meta description fallback, the solution was to migrate meaningful CPT text into post_excerpt so search engines receive cleaner, context‑aware snippets.

Earlier versions of these scripts artificially truncated content and appended ..., which introduced formatting issues (including awkward spacing before ellipses and cut‑off sentences). After review, the strategy was simplified: preserve the full semantic text and allow search engines or UI layers to truncate naturally when displaying snippets. This keeps excerpts readable in the admin while also producing stronger metadata for search.

For quotes, a controlled rebuild script was used to overwrite existing excerpts (many of which still contained legacy truncation artifacts) and regenerate them from the normalized plain‑text source.

Quote → Excerpt Migration Script

for id in $(wp post list \
  --post_type=quote \
  --post_status=any \
  --orderby=date \
  --order=DESC \
  --format=ids); do

  quote=$(wp post meta get $id quote_plain_text)

  if [ -n "$quote" ]; then

    clean=$(echo "$quote" | tr '\n' ' ' | tr -s ' ')

    echo "[$id] Rebuilding excerpt from quote_plain_text"

    wp post update $id --post_excerpt="$clean"

  else
    echo "[$id] Skipping (no quote_plain_text)"
  fi

done

How the script works

  • Loops through every Quote CPT entry using WP‑CLI and processes newest posts first (--orderby=date --order=DESC) for safer migration behavior.
  • For each post: retrieves the quote_plain_text custom field.
  • Line breaks are normalized into spaces (tr '\n' ' ').
  • Consecutive whitespace is compressed (tr -s ' '), preventing formatting oddities.
  • The cleaned text is written into post_excerpt.

Once migrated, Yoast automatically uses these excerpts as fallback meta descriptions for search snippets, meaning quote content now surfaces meaningfully in search engine previews without requiring manually authored SEO descriptions for every entry.

This establishes a repeatable architecture that can be reused across Lyrics, Excerpts, and other text‑heavy CPTs, allowing structured content to remain semantically rich while reducing SEO maintenance overhead.