How to Serve Clean Markdown Twins and Link Headers on WordPress

Full-bleed architectural ink-and-gouache illustration of twin leather drafting folios wired cleanly across a timber table beside a twilight industrial harbor.

About Will

I run Tygart Media, an AI-first agency that gets businesses cited and recommended by AI assistants — and I write about what we do, including what breaks.

Connect on LinkedIn →

From the Workbench · November 28, 2026 · By Will Tygart

Practitioner How-To · Free Takeaway
Download the 2-Page Spec PDF & Markdown Twin
Download the 2-page PDF architecture reference or grab the clean .md twin with the complete WordPress MU-plugin, Nginx MIME rules, and Python UTF-8 deployment checks.

When an engineer runs a prompt inside a terminal or IDE, their agent rarely wants fifty kilobytes of theme CSS, navigation menus, and inline scripts. Across our 31.8-day telemetry audit in Four AI Middlemen Out-Crawled Googlebot, a typical WordPress article page weighed 50,646 bytes uncompressed while its clean Markdown twin weighed just 8,515 bytes — a 5.9x payload reduction.

Wait until you check how different agents discover those files. In 3,405 Visits From Readers Without a Browser, CLI agents explicitly sent Accept: text/markdown headers and pulled 55 direct .md files cleanly. Meanwhile, bulk scrapers routinely ignored <head> tags unless visible links appeared in the HTML body or HTTP headers. Wiring all four rails onto the same canonical URL serves every client without splitting your SEO equity.

The Four Machine Discovery Rails on One Canonical URL

Never spin up separate per-bot directories or return cloaked HTML by User-Agent. Keep one canonical URL and expose the static .md twin uniformly across all four RFC 8288 and HTML pointers:

Discovery RailProtocol / LayerBest Consumer ClientsVerification Requirement
1. HTTP Link HeaderRFC 8288 Link header via PHP send_headersCLI terminals and headless fetchers checking HEAD/GETHeader present on single posts; zero duplicate Link headers on homepage
2. HTML Head Alternatelink rel='alternate' type='text/markdown'Standards-compliant crawlers and Markdown-aware browsersExact single tag count == 1 matching live HTTP 200 .md path
3. Schema.org encodingArticle JSON-LD MediaObject encodingFormat text/markdownStructured knowledge graphs and schema extractorsValid JSON-LD citing canonical contentUrl
4. Visible Body ButtonInline HTML anchor pointing directly to slug.mdSearch APIs and scrapers that ignore head metadataVerified 200 status and byte-exact SHA-256 against local source

For broader catalog indexing alongside per-post twins, also maintain an llms.txt index at your domain root — remembering never to overwrite a dynamic SEO plugin route with a static file if your stack already generates one dynamically.

Four-rail WordPress Markdown twin discovery diagram comparing 50,646-byte HTML payloads vs 8,515-byte LF UTF-8 Markdown files wired via Link HTTP header, HTML alternate tag, JSON-LD encoding, and visible button.
Publishing a canonical Markdown twin beside WordPress HTML cuts bot and terminal transfer size 5.9x across four discovery rails.

WordPress MU-Plugin to Emit Both Link Headers and Head Tags

Block themes omit Markdown alternate links by default, and WordPress core REST media uploads reject .md files with HTTP 500 rest_upload_sideload_error. Deploy .md files directly to your webroot over SSH/SFTP, then drop a compact Must-Use plugin inside wp-content/mu-plugins/ that checks disk existence before advertising the alternate URL:

wp-content/mu-plugins/site-markdown-alternate.php (No Global Vars Needed) (php)
<?php
/* Plugin Name: Markdown Twin Discovery Rail */
if (!defined('ABSPATH')) { exit; }
 
function tm_resolve_md_twin_url(): string {
    if (!is_singular('post') || is_front_page()) { return ''; }
    if (!get_post_field('post_name', get_queried_object_id())) { return ''; }
    if (!file_exists(ABSPATH . get_post_field('post_name', get_queried_object_id()) . '.md')) { return ''; }
    return home_url('/' . get_post_field('post_name', get_queried_object_id()) . '.md');
}
 
add_action('wp_head', function (): void {
    if (tm_resolve_md_twin_url() !== '') {
        echo '<link rel="alternate" type="text/markdown" href="' . esc_url(tm_resolve_md_twin_url()) . '">' . "\n";
    }
}, 1);
 
add_action('send_headers', function (): void {
    if (tm_resolve_md_twin_url() !== '') {
        header('Link: <' . esc_url_raw(tm_resolve_md_twin_url()) . '>; rel="alternate"; type="text/markdown"', false);
    }
}, 20);

Nginx MIME Configuration, UTF-8 Decoding, and Common Traps

Serving a Markdown twin as application/octet-stream forces terminals and browsers into download prompts instead of inline reading. Configure Nginx MIME types cleanly and guard against four silent deployment defects:

Markdown Twin TrapRoot Technical CauseConcrete SymptomOperational Fix
WP REST Media upload rejects .mdWordPress core blocks Markdown uploads via rest_upload_sideload_errorDeterministic HTTP 500 on POST /wp-json/wp/v2/mediaStage LF .md tarballs over SSH and install with web-user ownership
ISO-8859-1 smart-punctuation mojibakePython requests defaults charset-less text/* types to ISO-8859-1Em-dashes corrupt when reading resp.text instead of UTF-8 bytesSet Content-Type charset=utf-8 in Nginx and decode resp.content UTF-8
CRLF vs LF SHA-256 driftWindows editors write CRLF unless newline='\n' is forcedDisk file fails exact SHA-256 verification against Linux originForce newline='\n' on Python write_text and extract via tar -mxzf
Short italic byline before Direct AnswerChunkers score p[0] under H1 as opening passage densitySub-30-word byline tanks RAG readiness scores into low 50sPlace 45-55w Direct Answer paragraph immediately after H1 heading
Nginx Markdown MIME Block + Python UTF-8 Verification Check (python)
# 1. Nginx server block (text/markdown; charset=utf-8)
# location ~* \.md {
#     types { text/markdown md; }
#     default_type text/markdown;
#     charset utf-8;
#     charset_types text/markdown text/plain;
#     try_files /wp-content/uploads/md-cache =404;
# }
# (Simply point location at your static webroot file path with try_files uri =404)
 
# 2. Write explicit LF UTF-8 locally & decode strictly as UTF-8 on verify
import hashlib, pathlib, urllib.request
 
def publish_prepare_and_verify(md_text: str, out_path: pathlib.Path, live_url: str) -> None:
    clean = md_text.replace("\r\n", "\n")
    out_path.write_text(clean, encoding="utf-8", newline="\n")
    expected_sha = hashlib.sha256(out_path.read_bytes()).hexdigest()
    req = urllib.request.Request(live_url, headers={"User-Agent": "Mozilla/5.0"})
    with urllib.request.urlopen(req, timeout=15) as r:
        assert "markdown" in r.headers.get("Content-Type", "").lower()
        live_bytes = r.read()
        assert hashlib.sha256(live_bytes).hexdigest() == expected_sha

Keep one more habit mandatory across refreshes: whenever you update dates, prices, or benchmarks inside WordPress, regenerate its paired .md twin in the exact same release pass. Nothing burns terminal-agent trust faster than an HTML page updated in November paired with a stale September Markdown file, a gap we detailed in Do AI Crawlers Follow llms.txt and Markdown Twins.

Make Every How-To Pullable From a Terminal

Remember RFC 9110 content and caching rules: clear any page cache or reverse-proxy cache layer right after updating .md files and warm key URLs with GET requests rather than HEAD probes. When an engineer asks their coding agent for help mid-debug, a clean 8.5 KB Markdown spec arrives inside their editor before a bloated HTML page finishes rendering.

Frequently Asked Questions

Why not upload .md files through the standard WordPress Media Library REST endpoint?

WordPress core rejects Markdown file extensions on /wp-json/wp/v2/media with HTTP 500 rest_upload_sideload_error. Deploying static LF UTF-8 .md files directly to your webroot over SSH avoids core upload blocks and serves at full web-server speed.

Why advertise both HTTP Link headers and HTML alternate tags?

Different tools inspect different layers: CLI tools and API crawlers parse RFC 8288 Link headers or send Accept: text/markdown, while page-level parsers look for HTML <head> <link rel='alternate'> tags, JSON-LD encoding arrays, or visible anchors.

What causes smart dashes or quotes in Markdown files to garble in Python HTTP scripts?

HTTP clients like Python requests default charset-less text/plain responses to ISO-8859-1. Explicitly configuring charset utf-8; in Nginx and decoding raw bytes as UTF-8 keeps checksums and punctuation exact.

Primary Documentation & References

Continue the Workbench Series
Next practitioner wiring guide: How to Wire WordPress MCP for Grok, Claude, and Coding Terminals. For agent-ready content architecture and citation diagnostics, see our AI Citation Service or Smokejumpers Pricing.
Printable Workbench Reference
Keep This Wiring Spec Inside Your Repo
Download the 2-page PDF architecture reference or grab the clean .md twin with the complete WordPress MU-plugin, Nginx MIME rules, and Python UTF-8 deployment checks.
Track the AI tools you actually use
Vendor-neutral prices & limits for ChatGPT, Claude, Gemini, Perplexity and more — tracked in AI Stack Watch.
See the live AI tracker →

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *