How to Export WordPress Posts to Static HTML for External Translation Agencies
Export WordPress posts for an external translation agency by fetching each post’s content.rendered from the WordPress REST API and wrapping it in a standalone, UTF-8 HTML file. This gives the agency the reader-facing article rather than menus, theme markup, or Gutenberg editor data, but rendered HTML is a delivery format, not a lossless backup of the WordPress post.
Keep a separate manifest that maps each file to its WordPress post ID and source revision. Ask the agency to return the same HTML structure with translated text, then apply that text to a localized draft that retains the original blocks. Decide up front who handles image text, captions, links, excerpts, and SEO fields; those decisions are harder to reconstruct after translation starts.
Choose the WordPress Fields to Export
Use rendered HTML for the agency and retain an editor-format copy internally. A Gutenberg post may store a gallery, a reusable block reference, or a shortcode in post_content. On rendering, WordPress and its plugins turn those instructions into markup. That markup usually contains the words the translator needs, but it doesn’t preserve the instructions that generated them.
| Source | Use it for | What to watch for |
|---|---|---|
title.rendered | The translatable article headline | WordPress may return HTML entities such as ’; decode them before escaping the title as plain text. |
content.rendered | Body copy, headings, lists, tables, and captions rendered inside the post | Dynamic blocks may produce different output in a REST request than on the public page. |
content.raw | An internal editor-format snapshot, when available with authorized context=edit | It can contain block delimiters and shortcode syntax. Don’t substitute it for the agency file. |
excerpt.rendered | A separate translation field when the excerpt is in scope | It may be generated automatically. Check whether there’s a separately authored excerpt before paying to translate it twice. |
modified_gmt | A source revision marker in the manifest | Changes to shared blocks, media, or plugin-generated strings may not update the parent post’s timestamp. |
Never replace a block-based post’s
post_contentwith the agency’s rendered HTML if the localized post must remain editable as the original blocks.
Fetch One Published Post as JSON
Start with a representative article that contains more than paragraphs: a caption, a linked image, and a dynamic block make a better pilot. Set WP_ORIGIN to your site’s origin, without a trailing slash, and replace 123 with the numeric post ID. If WordPress is installed in a subdirectory, include that path in WP_ORIGIN.
post_id=123
mkdir -p wordpress-source agency-source
curl --fail --silent --show-error \
--get "$WP_ORIGIN/wp-json/wp/v2/posts/$post_id" \
--data-urlencode '_fields=id,slug,modified_gmt,title,content' \
--output "wordpress-source/post-$post_id.json"
The field filter keeps the response focused on the export and its identifiers. Check that the response is a post object before processing it; a disabled REST route, an authorization failure, or a login redirect can otherwise leave you with no usable content. On sites without pretty permalinks, try the equivalent route through ?rest_route=/wp/v2/posts/123.
The authenticated workflow for drafts is separate: fetch them through approved WordPress access and write the response to the same local JSON format. Don’t make an embargoed post public to export it, and don’t include the full authenticated REST response in an agency package.
Wrap the Rendered Post in a Standalone HTML File
Save the following program as export-post.py. It exports one post at a time, leaves the body markup intact, and puts the article headline in the body so the translator has one obvious place to edit it. The document’s browser-tab title is a nontranslatable tracking label, not the post’s SEO title.
# export-post.py
import argparse
import html
import json
import re
import sys
from pathlib import Path
def export_post(source: Path, destination: Path, lang: str, direction: str) -> None:
if source.resolve() == destination.resolve():
raise ValueError("Source and destination must be different files.")
if destination.suffix.lower() != ".html":
raise ValueError("Destination must have an .html extension.")
if not re.fullmatch(r"[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*", lang):
raise ValueError("Use a language tag such as en, fr-CA, or ar.")
post = json.loads(source.read_text(encoding="utf-8"))
if not isinstance(post, dict) or type(post.get("id")) is not int:
raise ValueError("Expected one WordPress REST post with a numeric ID.")
title_field, content_field = post.get("title"), post.get("content")
if not isinstance(title_field, dict) or not isinstance(content_field, dict):
raise ValueError("Missing title or content object.")
if content_field.get("protected"):
raise ValueError("Post content is flagged as protected; review it separately.")
title, body = title_field.get("rendered"), content_field.get("rendered")
if not isinstance(title, str) or not isinstance(body, str) or not body.strip():
raise ValueError("Expected a rendered title and a nonempty rendered body.")
headline = html.escape(html.unescape(title))
post_id = post["id"]
document = f"""<!doctype html>
<html lang="{lang}" dir="{direction}">
<head>
<meta charset="utf-8">
<title translate="no">WordPress post {post_id}</title>
</head>
<body>
<article data-wp-post-id="{post_id}">
<h1>{headline}</h1>
<div class="post-body">
{body}
</div>
</article>
</body>
</html>
"""
with destination.open("x", encoding="utf-8", newline="\n") as output:
output.write(document)
def main() -> int:
parser = argparse.ArgumentParser(
description="Wrap a WordPress REST post in standalone HTML."
)
parser.add_argument("source", type=Path)
parser.add_argument("destination", type=Path)
parser.add_argument("--lang", required=True)
parser.add_argument("--dir", choices=("ltr", "rtl"), default="ltr")
args = parser.parse_args()
try:
export_post(args.source, args.destination, args.lang, args.dir)
except (OSError, ValueError) as exc:
print(f"Export failed: {exc}", file=sys.stderr)
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())
The program decodes entities in the headline and then escapes the result so punctuation displays correctly without turning title text into markup. It deliberately does not escape or sanitize the rendered body: escaping it would expose every tag as text, and sanitizing it could remove content the translator needs. Inspect the output before sharing it, especially if custom filters add markup to titles or embeds to the body.
python3 export-post.py \
wordpress-source/post-123.json \
agency-source/post-123.en.html \
--lang en --dir ltr
Pass the language and direction of the source text, not the target locale. The destination directory must already exist, and the program refuses to overwrite an existing file; use a new delivery directory when exporting a revised source. Open the result and compare the headline and article body with the public post, not just the JSON response.
Make Agency Files Portable Without Losing Context
A standalone HTML document doesn’t automatically make its assets portable. For example, /wp-content/uploads/control-panel.png points to the WordPress site when the post is online but resolves against the wrong root when the agency opens the file locally. For offline packages, copy approved assets into an assets/ directory and update the references. If the agency can access approved hosted assets, absolute URLs can work instead.
<!-- Broken in an offline package: site-relative image path -->
<figure class="wp-block-image">
<img src="/wp-content/uploads/control-panel.png" alt="The export control panel">
<figcaption>Choose a file format before exporting.</figcaption>
</figure>
<!-- Fixed for a package with an assets directory beside the HTML -->
<figure class="wp-block-image">
<img src="assets/control-panel.png" alt="The export control panel">
<figcaption>Choose a file format before exporting.</figcaption>
</figure>
The fixed example changes the asset location without changing the caption or alternative text. In real exports, also check srcset, <source srcset>, and plugin-generated lazy-loading attributes; moving only src can leave other image candidates pointing at the original site. Keep a record of packaging rewrites so temporary paths don’t carry over into WordPress.
Give the agency a small manifest with one record per file. The values below are illustrative; copy the actual timestamp and slug from the WordPress response. Keep the original source filename stable and require a distinct return filename for each locale.
{
"post_id": 123,
"source_slug": "export-settings",
"source_modified_gmt": "2026-04-10T14:30:00",
"source_file": "post-123.en.html",
"return_file": "post-123.fr-CA.html",
"source_locale": "en",
"target_locale": "fr-CA",
"translate": ["article headline", "body text", "captions", "nonempty alt text"],
"preserve": ["element structure", "IDs", "classes", "URLs", "data attributes"],
"separate_fields": ["excerpt", "SEO title", "meta description", "localized slug"]
}
The manifest ties return files to source posts without asking anyone to infer identity from a translated title or slug. It also distinguishes fields that aren’t included in the HTML from fields the translator must preserve. Give the agency an explicit exception list if it should rewrite certain links or localize specific attribute values.
Never translate fragment identifiers or link destinations as ordinary text. A localized destination needs an approved URL mapping, and any change to an
idmust be reflected in every link that targets it.
Test the Return Files and Restore Text to WordPress
Round-trip one post through the agency’s actual translation tool before sending a batch. Some tools skip attributes, rewrite markup, or don’t honor translate="no". Use HTML Translate to preview a representative export and spot-check how captions and surrounding tags appear after translation.
- Open both files locally and check every heading, list, table, and figure. Confirm that the return file retains
data-wp-post-idand declares the targetlang, withdir="rtl"for right-to-left content where appropriate. - Compare structures, not just line counts. Check that
id,href, and asset references survived, while visible link labels and nonemptyaltvalues were translated. Keep decorativealt=""empty. - Compare the current
modified_gmtwith the manifest and verify any shared content that could have changed independently. Resolve source edits before transferring translated text. - Create or update the target-language draft through your multilingual setup. Transfer translated copy into the existing blocks and enter the localized title, slug, and SEO fields in their own controls. Preview the draft in WordPress to test theme styles, responsive media, and plugin behavior that the static file cannot reproduce.
Common Export and Handoff Mistakes
- The export includes navigation and cookie banners. A full-page save captured the theme. Start with
content.renderedand commission site-wide strings separately. - A signup prompt is absent. It may come from a theme template or a client-side widget rather than the post. Compare the public page with
content.renderedand send the widget strings as a separate item. - The localized draft shows block validation warnings. Rendered output was pasted over Gutenberg serialization. Restore the original blocks and apply translated text through their editable fields instead of replacing
post_content. - Accents appear as garbled characters. The saved bytes and declared encoding disagree. Keep both the actual file and
<meta charset="utf-8">in UTF-8, including after agency export. - Images work on the site but fail at the agency. The package still depends on site-relative or restricted URLs in
srcorsrcset. Rewrite approved references and test from a fresh copy of the package. - The localized article links back to source-language posts. The agency correctly preserved
href. Apply the approved locale-to-URL mapping during the WordPress import or editorial pass.
HTML File Translation Questions
Can you use the WordPress export XML instead?
Use WordPress export XML for a WordPress-to-WordPress transfer or when the agency explicitly supports that format. For an HTML-based translation workflow, content.rendered gives the agency the visible article without asking it to interpret WordPress-specific serialization.
Does the export include custom fields or SEO metadata?
Not by default. A custom field appears in content.rendered only if it is rendered into the post body. Export translatable custom fields and SEO values separately, using your plugin’s supported field names and preserving the association with the post ID.
Can you export pages with the same program?
Yes. Fetch a single page from /wp-json/wp/v2/pages/123 with the same requested fields. The wrapper still exports the body only; copy from a page template, header, or footer needs a separate handoff.
Should the agency translate text baked into screenshots?
Only if image localization is in scope. Translating alt and figcaption won’t change text inside the pixels. Supply editable artwork or request replacement screenshots and record those deliverables in the manifest.
What if a plugin renders different markup in REST and on the public page?
Identify the difference before sending the batch. For text that is missing from content.rendered, export the plugin’s editable strings separately or capture the relevant article section from an approved preview. Verify the capture excludes site chrome and any visitor-specific content.
Can the returned HTML be published as a static page?
The agency wrapper is a translation carrier, not a publishing template. If the destination is a static site, put the translated body into the production template and configure the real page title, locale, canonical URL, and any reciprocal hreflang links there.