Skip to content

harshanas/page-to-md

Repository files navigation

Page to MD

Automatically serves Markdown versions of all WordPress pages and posts. Append .md to any post/page URL to get its Markdown representation.

Description

Page to MD lets you access any WordPress page or post as clean Markdown by simply appending .md to its URL.

For example, if your post lives at https://example.com/hello-world, visiting https://example.com/hello-world.md will return a Markdown version complete with YAML front-matter metadata.

Page to MD — WordPress post (left) and its Markdown output (right)

Features

  • Zero configuration — activate the plugin and every public post/page instantly gets a .md endpoint.
  • YAML front-matter — each Markdown response includes title, date, author, and excerpt metadata.
  • Built-in caching — converted Markdown is cached using the WordPress Transients API and automatically invalidated when a post is updated.
  • Hierarchical pages — supports parent/child page structures (e.g. parent/child.md).
  • Password-protected posts — returns a 403 response instead of leaking protected content.
  • Proper HTTP headers — serves text/markdown content type, Last-Modified, and Cache-Control headers.
  • Developer-friendly — multiple filters available to customise post types, cache TTL, cache keys, and more.

Use Cases

  • Feed your WordPress content into static site generators or documentation tools.
  • Provide a machine-readable Markdown API for your content.
  • Enable AI tools and LLMs to consume your content in a clean text format.
  • Back up or migrate content in Markdown format.

Requirements

  • WordPress 5.0 or higher
  • PHP 7.4 or higher

Installation

Download from GitHub (recommended)

  1. Go to the Releases page and download the latest .zip file.
  2. Upload the zip via Plugins → Add New → Upload Plugin in WordPress, or extract the page-to-md folder into /wp-content/plugins/.
  3. Activate the plugin through the Plugins screen in WordPress.
  4. That's it! Append .md to any post or page URL to get the Markdown version.

From source

The release zip includes all required dependencies. If you clone the repository directly, you'll need to install them yourself:

  1. Clone the repository into /wp-content/plugins/:
    git clone https://github.com/harshanas/page-to-md.git
  2. Install Composer dependencies:
    cd page-to-md
    composer install --no-dev
  3. Activate the plugin through the Plugins screen in WordPress.

Frequently Asked Questions

How do I access the Markdown version of a post?

Simply add .md to the end of any post or page URL. For example:

https://example.com/my-post.md

Does it work with custom post types?

By default, only post and page types are supported. You can add custom post types using the page_to_md_allowed_post_types filter:

add_filter( 'page_to_md_allowed_post_types', function ( $types ) {
    $types[] = 'product';
    return $types;
} );

Does it work with hierarchical (nested) pages?

Yes. If your page URL is https://example.com/parent/child, the Markdown URL is https://example.com/parent/child.md.

Are password-protected posts accessible?

No. Password-protected posts return a 403 Forbidden response when accessed via the .md endpoint.

Can I change the cache duration?

Yes. Use the page_to_md_cache_ttl filter:

add_filter( 'page_to_md_cache_ttl', function ( $ttl, $post_id ) {
    return 2 * HOUR_IN_SECONDS;
}, 10, 2 );

Is the cache automatically cleared when I update a post?

Yes. The cache is invalidated whenever a post is saved, updated, or trashed.

Do I need to flush permalinks after activation?

No. The plugin automatically flushes rewrite rules on activation.

Filters

Filter Description Default
page_to_md_allowed_post_types Control which post types can be served as Markdown. ['post', 'page']
page_to_md_cache_ttl Adjust the cache lifetime in seconds. 3600 (1 hour)
page_to_md_cache_key_parts Add custom components to the cache key (e.g. user role). []
page_to_md_use_cache Enable or disable caching per request. true

Changelog

1.0.0

  • Initial release.
  • Markdown endpoint for posts and pages via .md URL suffix.
  • YAML front-matter with title, date, author, and excerpt.
  • Transient-based caching with automatic invalidation.
  • Support for hierarchical page slugs.
  • Password-protected post handling.
  • Developer filters for post types, cache TTL, cache keys, and cache toggling.

License

This plugin is licensed under the GPLv2 or later.

About

A WordPress plugin which automatically serves Markdown versions of all WordPress pages and posts. Append .md to any post/page URL to get its Markdown representation.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors