PHPackages                             roots/post-content-to-markdown - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. roots/post-content-to-markdown

ActiveWordpress-plugin[Parsing &amp; Serialization](/categories/parsing)

roots/post-content-to-markdown
==============================

A WordPress plugin that serves post content as Markdown via Accept headers or query parameters.

v1.7.1(2mo ago)571.1k2[1 issues](https://github.com/roots/post-content-to-markdown/issues)MITPHPPHP ^8.1CI passing

Since Oct 3Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/roots/post-content-to-markdown)[ Packagist](https://packagist.org/packages/roots/post-content-to-markdown)[ Docs](https://roots.io/sage/)[ GitHub Sponsors](https://github.com/roots)[ RSS](/packages/roots-post-content-to-markdown/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (12)Versions (16)Used By (0)

Post Content to Markdown
========================

[](#post-content-to-markdown)

[![Packagist Installs](https://camo.githubusercontent.com/b976e9c7765424710f75cf83334b1a742dca0c4332c7009415ec032405b69b97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6f74732f706f73742d636f6e74656e742d746f2d6d61726b646f776e3f6c6162656c3d7061636b6167697374253230696e7374616c6c7326636f6c6f72423d32623330373226636f6c6f72413d353235646463267374796c653d666c61742d737175617265)](https://packagist.org/packages/roots/post-content-to-markdown)[![GitHub downloads](https://camo.githubusercontent.com/35b7528326ca86526dabf8f547765b53f718c2388b3b11c17566e002ebfc603d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f726f6f74732f706f73742d636f6e74656e742d746f2d6d61726b646f776e2f746f74616c3f6c6162656c3d676974687562253230646f776e6c6f616473267374796c653d666c61742d737175617265)](https://github.com/roots/post-content-to-markdown/releases)[![Try in Playground](https://camo.githubusercontent.com/bf90900de36a569c8d95e1118acc99fd9cc05c6741ef8c20d6be04727fa62542/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f747279253230696e253230706c617967726f756e642d3338353865393f6c6f676f3d776f72647072657373266c6f676f436f6c6f723d666666666666266d6573736167653d267374796c653d666c61742d737175617265)](https://playground.wordpress.net/#%7B%22$schema%22:%22https://playground.wordpress.net/blueprint-schema.json%22,%22landingPage%22:%22/hello-world.md%22,%22preferredVersions%22:%7B%22php%22:%22latest%22,%22wp%22:%22latest%22%7D,%22steps%22:%5B%7B%22step%22:%22setSiteOptions%22,%22options%22:%7B%22permalink_structure%22:%22/%25postname%25/%22%7D%7D,%7B%22step%22:%22installPlugin%22,%22pluginData%22:%7B%22resource%22:%22url%22,%22url%22:%22https://github.com/roots/post-content-to-markdown/releases/latest/download/post-content-to-markdown.zip%22%7D,%22options%22:%7B%22activate%22:true%7D%7D%5D%7D)[![Follow Roots](https://camo.githubusercontent.com/222256dbdeac58e77f017d847dca30ff4cab027cdf3abfec8e5bfd59de240547/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f666f6c6c6f7725323040726f6f747377702d3164613166323f6c6f676f3d74776974746572266c6f676f436f6c6f723d666666666666266d6573736167653d267374796c653d666c61742d737175617265)](https://twitter.com/rootswp)[![Sponsor Roots](https://camo.githubusercontent.com/31e13361135ff96d01f1eb97157d052029e6f236249996072d8b6bd60b40e9cd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f72253230726f6f74732d3532356464633f6c6f676f3d676974687562267374796c653d666c61742d737175617265266c6f676f436f6c6f723d666666666666266d6573736167653d)](https://github.com/sponsors/roots)

A WordPress plugin that returns post content in Markdown format when requested with an `Accept` header set to `text/markdown`, a `.md` URL suffix (e.g. `/hello-world.md`), or a `?format=markdown` query parameter.

Tip

Learn more about serving Markdown to AI agents and check your site's AI-readiness at [acceptmarkdown.com](https://acceptmarkdown.com/).

See the acceptmarkdown.com score when using this plugin[![](https://camo.githubusercontent.com/65a334071207befd36295ad84ce47af16631f5d8d2c5b8cd84641b3ace15da5e/68747470733a2f2f726f6f74732e696f2f6170702f75706c6f6164732f73636f7265636172642d726f6f74732d696f2d73657276652d796f75722d776f726470726573732d706f7374732d61732d6d61726b646f776e2e706e67)](https://acceptmarkdown.com/)

`.md` URL / Query Parameter[`text/markdown` Accept header](https://acceptmarkdown.com/)[![Screenshot of the plugin output on WP's default Hello World post](https://camo.githubusercontent.com/dee4d657396006b89fc2df3b3cd3e31f8d0676114b661de78e844e0015152ca8/68747470733a2f2f63646e2e726f6f74732e696f2f6170702f75706c6f6164732f706f73742d636f6e74656e742d746f2d6d61726b646f776e2d68656c6c6f2d776f726c642e706e67)](https://camo.githubusercontent.com/dee4d657396006b89fc2df3b3cd3e31f8d0676114b661de78e844e0015152ca8/68747470733a2f2f63646e2e726f6f74732e696f2f6170702f75706c6f6164732f706f73742d636f6e74656e742d746f2d6d61726b646f776e2d68656c6c6f2d776f726c642e706e67)[![Screenshot of the plugin output on WP's default Hello World post (Accept header)](https://camo.githubusercontent.com/055ffbe1e5588e6dc78a3bcd05ad506bfa3ea978aecb53fa452571763d59db3d/68747470733a2f2f63646e2e726f6f74732e696f2f6170702f75706c6f6164732f706f73742d636f6e74656e742d746f2d6d61726b646f776e2d68656c6c6f2d776f726c642d6375726c2e706e67)](https://camo.githubusercontent.com/055ffbe1e5588e6dc78a3bcd05ad506bfa3ea978aecb53fa452571763d59db3d/68747470733a2f2f63646e2e726f6f74732e696f2f6170702f75706c6f6164732f706f73742d636f6e74656e742d746f2d6d61726b646f776e2d68656c6c6f2d776f726c642d6375726c2e706e67)Support us
----------

[](#support-us)

Roots is an independent open source org, supported only by developers like you. Your sponsorship funds [WP Packages](https://wp-packages.org/) and the entire Roots ecosystem, and keeps them independent. Support us by purchasing [Radicle](https://roots.io/radicle/) or [sponsoring us on GitHub](https://github.com/sponsors/roots) — sponsors get access to our private Discord.

Requirements
------------

[](#requirements)

PHP 8.1+

Installation
------------

[](#installation)

### via Composer

[](#via-composer)

```
composer require roots/post-content-to-markdown
```

### Manual

[](#manual)

1. Download the [latest release](https://github.com/roots/post-content-to-markdown/releases)
2. Place in `wp-content/plugins/post-content-to-markdown/`
3. Activate via wp-admin or WP-CLI

Usage
-----

[](#usage)

### Accept headers (ideal for AI agents)

[](#accept-headers-ideal-for-ai-agents)

Send an `Accept: text/markdown` header to any of these URLs:

- **Single post:** `https://example.com/post-slug/` → Returns post content as Markdown
- **Single post with comments:** `https://example.com/post-slug/feed/` → Returns post + all comments
- **Main feed:** `https://example.com/feed/` → Returns latest posts as Markdown

**Examples:**

```
# Single post
curl -H "Accept: text/markdown" https://example.com/my-awesome-post/

# Single post with comments
curl -H "Accept: text/markdown" https://example.com/my-awesome-post/feed/

# Main feed
curl -H "Accept: text/markdown" https://example.com/feed/
```

### `.md` URL suffix

[](#md-url-suffix)

Appending `.md` to any permalink returns the same Markdown representation and is a first-class, shareable URL.

```
# Equivalent to Accept: text/markdown
curl https://example.com/my-awesome-post.md
```

`.md` URL responses include `X-Robots-Tag: noindex, nofollow` so search engines don't index the Markdown alias alongside the canonical HTML page. Disable this feature with the `post_content_to_markdown/md_url_enabled` filter.

HTML responses advertise the Markdown representation two ways so both RFC 8288-aware crawlers and HTML-parsing clients can discover it without sending `Accept: text/markdown`:

```
Link: ; rel="alternate"; type="text/markdown"

```

```

```

### Query parameter

[](#query-parameter)

For browsers and sharing, use the `?format=markdown` query parameter:

- **Single post:** `https://example.com/post-slug/?format=markdown`
- **Single post with comments:** `https://example.com/post-slug/feed/?format=markdown`
- **Main feed:** `https://example.com/feed/?format=markdown`

**Examples:**

```
# View in browser
https://example.com/my-awesome-post/?format=markdown

# Get post with comments
https://example.com/my-awesome-post/feed/?format=markdown

# Get main feed
https://example.com/feed/?format=markdown
```

### Response headers

[](#response-headers)

Markdown responses carry:

- `Content-Type: text/markdown; charset=utf-8`
- `Vary: Accept` — tells caches to key by `Accept` so the HTML and Markdown representations don't cross-serve.
- `X-Markdown-Source: accept | md-url | query` — identifies how the client asked for Markdown. Useful for inspecting agent traffic in access logs.

### Dedicated Markdown feed

[](#dedicated-markdown-feed)

A dedicated Markdown feed is also available at `/feed/markdown/`:

```
curl https://example.com/feed/markdown/
```

The feed includes:

- Feed metadata (site name, description, last updated, feed URL)
- Post title, author, publication date (ISO 8601), and permalink
- Post categories and tags
- Post content converted to Markdown
- Optional excerpt support
- Optional comment support

**Example Output:**

```
# My WordPress Site - Markdown Feed

**Description:** Just another WordPress site
**Last Updated:** 2025-10-03T19:45:00+00:00
**Feed URL:** https://example.com/feed/markdown/

---

# Hello World!

**Author:** John Doe
**Published:** 2025-10-03T12:00:00+00:00
**URL:** https://example.com/hello-world/
**Categories:** News, Updates
**Tags:** announcement, wordpress

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

---
```

**Feed URL structure:**

Markdown feeds are accessible via:

- `/feed/markdown/` - Dedicated Markdown feed
- `/feed/?format=markdown` or `/feed/` with `Accept: text/markdown` - Main feed as Markdown
- `/post-slug/feed/?format=markdown` or `/post-slug/feed/` with `Accept: text/markdown` - Single post with comments

Note that WordPress requires pretty permalinks to be enabled (Settings → Permalinks must be set to anything other than "Plain").

**Autodiscovery:**

The plugin automatically adds a `` element to your site's RSS feed, allowing feed readers and AI agents to discover the Markdown version:

```

```

Filters
-------

[](#filters)

The plugin provides several filters for customization:

### Single post filters

[](#single-post-filters)

#### `post_content_to_markdown/post_types`

[](#post_content_to_markdownpost_types)

Filter the post types that can be served as Markdown for single posts.

```
add_filter('post_content_to_markdown/post_types', function ($post_types) {
    // Add support for pages and custom post types
    return ['post', 'page', 'product'];
});
```

**Default:** `['post']`

#### `post_content_to_markdown/post_allowed`

[](#post_content_to_markdownpost_allowed)

Filter whether a specific post is allowed to be served as Markdown. Runs after the post type check, so it only receives posts whose type is already allowed. Returning `false` short-circuits the Markdown response and falls through to the normal HTML render.

```
add_filter('post_content_to_markdown/post_allowed', function ($allowed, $post) {
    // Only serve Markdown for specific page slugs
    if ($post->post_type === 'page') {
        return in_array($post->post_name, ['example', 'example-2'], true);
    }

    return $allowed;
}, 10, 2);
```

Or restrict by post ID:

```
add_filter('post_content_to_markdown/post_allowed', function ($allowed, $post) {
    if ($post->post_type === 'page') {
        return in_array($post->ID, [1, 2, 3], true);
    }

    return $allowed;
}, 10, 2);
```

**Default:** `true`

#### `post_content_to_markdown/md_url_enabled`

[](#post_content_to_markdownmd_url_enabled)

Controls whether `.md` URL suffixes (e.g. `/about.md`) are treated as a Markdown request. Enabled by default so consumers get shareable Markdown URLs automatically. Disable if you'd rather only accept Markdown requests via the `Accept` header or `?format=markdown` query parameter.

```
add_filter('post_content_to_markdown/md_url_enabled', '__return_false');
```

**Default:** `true`

#### `post_content_to_markdown/strict_accept`

[](#post_content_to_markdownstrict_accept)

Controls whether the plugin returns `406 Not Acceptable` when the client's `Accept` header rules out every representation the site can serve (i.e. neither `text/html` nor `text/markdown` is acceptable). Enabled by default for spec-correct content negotiation. Disable if you'd rather always fall back to HTML for any `Accept` value.

```
add_filter('post_content_to_markdown/strict_accept', '__return_false');
```

**Default:** `true`

#### `post_content_to_markdown/emit_vary`

[](#post_content_to_markdownemit_vary)

Controls whether the plugin appends `Vary: Accept` to every front-end response. Enabled by default so that downstream caches (browsers, proxies, CDNs) key on the Accept header and don't cross-serve an HTML response to a Markdown request (or vice versa). Disable if you don't want the plugin touching HTML response headers — Markdown responses will still include `Vary: Accept` regardless, so content negotiation stays correct for direct Markdown hits.

```
add_filter('post_content_to_markdown/emit_vary', '__return_false');
```

**Default:** `true`

#### `post_content_to_markdown/cache_md_urls`

[](#post_content_to_markdowncache_md_urls)

By default the plugin sets `DONOTCACHEPAGE` for every Markdown request so WordPress page caches (WP Super Cache, Batcache, etc.) don't cross-serve a Markdown body to an HTML client. `.md` URLs are a distinct URL key and safe to cache in principle, but WP page caches can transform response bodies assuming HTML (gzip, footer injection, cache-comment insertion), so caching them is opt-in. Enable if your page cache passes non-HTML bodies through untouched.

```
add_filter('post_content_to_markdown/cache_md_urls', '__return_true');
```

**Default:** `false`

### Feed filters

[](#feed-filters)

#### `post_content_to_markdown/feed_post_types`

[](#post_content_to_markdownfeed_post_types)

Filter the post types included in the Markdown feed.

```
add_filter('post_content_to_markdown/feed_post_types', function ($post_types) {
    return ['post', 'page'];
});
```

**Default:** `['post']`

#### `post_content_to_markdown/feed_posts_per_page`

[](#post_content_to_markdownfeed_posts_per_page)

Filter the number of posts included in the Markdown feed.

```
add_filter('post_content_to_markdown/feed_posts_per_page', function ($count) {
    return 20;
});
```

**Default:** `10`

#### `post_content_to_markdown/feed_include_comments`

[](#post_content_to_markdownfeed_include_comments)

Enable or disable comments in the Markdown feed.

```
add_filter('post_content_to_markdown/feed_include_comments', function () {
    return true;
});
```

**Default:** `false`

#### `post_content_to_markdown/feed_include_excerpt`

[](#post_content_to_markdownfeed_include_excerpt)

Enable or disable post excerpts in the Markdown feed.

```
add_filter('post_content_to_markdown/feed_include_excerpt', function () {
    return true;
});
```

**Default:** `false`

#### `post_content_to_markdown/feed_cache_duration`

[](#post_content_to_markdownfeed_cache_duration)

Filter the cache duration for the Markdown feed in seconds.

```
add_filter('post_content_to_markdown/feed_cache_duration', function ($duration) {
    return 2 * HOUR_IN_SECONDS; // Cache for 2 hours
});
```

**Default:** `HOUR_IN_SECONDS` (1 hour)

### Conversion filters

[](#conversion-filters)

#### `post_content_to_markdown/conversion_cache_duration`

[](#post_content_to_markdownconversion_cache_duration)

Filter the cache duration for the HTML → Markdown conversion result in seconds. The conversion is memoized per content hash in the object cache; shorten this TTL if your content renders dynamically (e.g. dynamic blocks, request-aware shortcodes) and you want fresher output.

```
add_filter('post_content_to_markdown/conversion_cache_duration', function ($duration) {
    return 5 * MINUTE_IN_SECONDS;
});
```

**Default:** `HOUR_IN_SECONDS` (1 hour)

#### `post_content_to_markdown/converter_options`

[](#post_content_to_markdownconverter_options)

Filter the HTML to Markdown converter options.

```
add_filter('post_content_to_markdown/converter_options', function ($options) {
    return [
        'header_style' => 'setext',           // Use underline style for H1/H2
        'strip_tags' => false,                // Keep HTML tags without markdown equivalents
        'remove_nodes' => 'script style img', // Remove script, style, and img elements
        'hard_break' => false,                // Convert  to two spaces + newline
    ];
});
```

**Available options:**

- `header_style`: `'atx'` (default) or `'setext'`
- `strip_tags`: Remove HTML tags without Markdown equivalents (default: `true`)
- `remove_nodes`: Space-separated list of DOM nodes to remove (default: `'script style'`)
- `hard_break`: Convert `` to newlines (default: `true`)

#### `post_content_to_markdown/markdown_output`

[](#post_content_to_markdownmarkdown_output)

Filter the final Markdown output after conversion.

```
add_filter('post_content_to_markdown/markdown_output', function ($markdown, $original_html) {
    // Add a footer to all Markdown output
    return $markdown . "\n\n---\nConverted from HTML to Markdown";
}, 10, 2);
```

**Parameters:**

- `$markdown`: The converted Markdown text
- `$original_html`: The original HTML content

Performance
-----------

[](#performance)

The HTML → Markdown conversion is cached at the object-cache layer (`wp_cache_get` / `wp_cache_set`) keyed on a content hash. Sites with a persistent object cache like Redis or Memcached avoid re-running block rendering, shortcode expansion, and the `league/html-to-markdown` conversion on repeat hits. Cache entries expire after an hour (filterable via `post_content_to_markdown/conversion_cache_duration`); content changes produce a new hash and a fresh entry, so no explicit invalidation is needed.

The cache assumes that rendering the same post content produces the same output. If you use dynamic blocks or shortcodes whose output varies by request context (e.g. current user, current time, site option that changes mid-TTL), the first render is frozen for the TTL window. Shorten the TTL via the filter above for content where that matters. The `post_content_to_markdown/markdown_output` filter runs on every request (after the cache lookup), so per-request customization there works without fighting the cache.

The Markdown feed is cached for 1 hour by default via a transient. The cache is automatically cleared when:

- A post is published or updated
- A post is deleted
- Comments are added, edited, or deleted (when comments are included in feed)

You can customize the cache duration using the `post_content_to_markdown/feed_cache_duration` filter.

Resources
---------

[](#resources)

- [acceptmarkdown.com](https://acceptmarkdown.com/) — serving Markdown to AI agents via content negotiation, plus a readiness check for your site
- [RFC 9110 §12.5.1 — Proactive Negotiation](https://www.rfc-editor.org/rfc/rfc9110#name-proactive-negotiation)
- [RFC 7763 — The `text/markdown` Media Type](https://www.rfc-editor.org/rfc/rfc7763)
- [RFC 8288 — Web Linking](https://www.rfc-editor.org/rfc/rfc8288) (the `Link` header and `rel="alternate"`)
- [MDN — Content negotiation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Content_negotiation)

Community
---------

[](#community)

Keep track of development and community news.

- Join us on Discord by [sponsoring us on GitHub](https://github.com/sponsors/roots)
- Join us on [Roots Discourse](https://discourse.roots.io/)
- Follow [@rootswp on Twitter](https://twitter.com/rootswp)
- Follow the [Roots Blog](https://roots.io/blog/)
- Subscribe to the [Roots Newsletter](https://roots.io/subscribe/)

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance87

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Recently: every ~0 days

Total

12

Last Release

76d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f3f71fa88954b93f55af5e121f1d8c38d240a0d17712c092a389bcccffa34415?d=identicon)[retlehs](/maintainers/retlehs)

---

Top Contributors

[![retlehs](https://avatars.githubusercontent.com/u/115911?v=4)](https://github.com/retlehs "retlehs (38 commits)")

---

Tags

content-negotiationhtml-to-markdownllmsmarkdownwordpresswordpress-plugin

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/roots-post-content-to-markdown/health.svg)

```
[![Health](https://phpackages.com/badges/roots-post-content-to-markdown/health.svg)](https://phpackages.com/packages/roots-post-content-to-markdown)
```

###  Alternatives

[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)[verbb/formie

The most user-friendly forms plugin for Craft.

102393.6k69](/packages/verbb-formie)[spatie/laravel-markdown-response

Serve markdown versions of your HTML pages to AI agents and bots

7655.9k6](/packages/spatie-laravel-markdown-response)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)[forumify/forumify-platform

122.0k14](/packages/forumify-forumify-platform)[jolicode/jolimarkdown

A markdown fixer, for enforcing a consistent style in your markdown files.

151.1k](/packages/jolicode-jolimarkdown)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
